자바에서 테스트 코드를 작성하다보면,
org.assertj.core.api.Assertions라는 클래스를 참 많이 쓰게 된다.
우선, Assertions.java를 들어가면 아래와 같은 설명이 나온다.
Entry point for assertion methods for different types. Each method in this class is a static factory for a type-specific assertion object.
For example:
int removed = employees.removeFired();
assertThat(removed).isZero();
List<Employee> newEmployees = employees.hired(TODAY);
assertThat(newEmployees).hasSize(6);
This class only contains all assertThat methods, if you have ambiguous method compilation error, use either AssertionsForClassTypes or AssertionsForInterfaceTypes and if you need both, fully qualify you assertThat method.
Java 8 is picky when choosing the right assertThat method if the object under test is generic and bounded, for example if foo is instance of T that extends Exception, java 8 will complain that it can't resolve the proper assertThat method (normally assertThat(Throwable) as foo might implement an interface like List, if that occurred assertThat(List) would also be a possible choice - thus confusing java 8.
This why Assertions have been split in AssertionsForClassTypes and AssertionsForInterfaceTypes
Author:
Alex Ruiz, Yvonne Wang, David DIDIER, Ted Young, Joel Costigliola, Matthieu Baechler, Mikhail Mazursky, Nicolas François, Julien Meddah, William Bakker, William Delanoue
단언문을 표현하는 클래스라는 설명으로 요약이 가능하다
우선, 인텔리제이 한정 해결방법은 import 뒤에 static을 추가해서,
import static org.assertj.core.api.Assertions.*;
으로 쓰면 해결이 가능하다
'Portpolio > webdev_tip' 카테고리의 다른 글
git과 linux의 관계 (0) | 2023.06.16 |
---|---|
github의 watch 기능은 뭘까? (0) | 2023.06.13 |
intellij 생성자 단축키 (0) | 2023.05.29 |
c언어와 c++의 차이는? (0) | 2023.05.02 |
[tip] 코테 시간 제한 통과하는 방법 (0) | 2023.04.28 |
댓글