728x90
728x90
extracting
-
[SpringBootTest] AssertJ List의 원하는 컬럼만 가져와서 포함됐는지 안됐는지 확인하기 - extracting/containsExactlyJAVA/Spring(Springboot) 2023. 4. 5. 14:47
이름(username)과 나이(age) 필드를 가진 Member라는 클래스가 있다. List result = new ArrayList(); result.add(new Member("memberA", 10)); result.add(new Member("memberB", 20)); 이때 resullt에 username에 "memberA"가 포함되었는지 확인할 수 있다. Assertions.assertThat( 리스트 ).extracting( 원하는 컬럼 ).containsExactly( 값 ); 문법을 사용하면 된다. Assertions.assertThat(result) .extracting("username") .containsExactly("memberA") .doesNotContain("teamC");..