AssertJ()이란

G-NOTE·2021년 11월 2일
0

Spring

목록 보기
13/14

AssertJ란 무엇인가

Q. What is AssertJ Core?
AssertJ is a Java library that provides a rich set of assertions and truly helpful error messages, improves test code readability, and is designed to be super easy to use within your favorite IDE.
(https://assertj.github.io/doc/)

  • AssertJ란 다양한 assertion과 유용한 에러 메세지를 제공하여 테스트 코드의 가독성을 높이고, 원하는 개발 환경에서 사용하기 쉽게 설계된 자바 라이브러리이다.

AssertJ 메서드 import하기

import static org.junit.jupiter.api.Assertions.*;
import static org.assertj.core.api.Assertions.*;

예시)

Member findMember = memberService.findOne(saveId).get();
// member의 이름이 findMember의 이름과 같은가?
// Assertions 생략 가능
assertThat(member.getName()).isEqualTo(findMember.getName());
  • static 키워드를 사용해서 import하면 클래스 이름을 적지 않고 사용 가능하다.

AssertJ 메서드 사용하기

assertThat(actual).isEqualTo(expected);
assertThat(1).isEqualTo(2);
  • assertThat(Object o)로 테스트할 객체를 호출한 뒤 메서드를 사용한다.

참조

https://assertj.github.io/doc/
https://steady-coding.tistory.com/351

profile
FE Developer

0개의 댓글