💡 이 글은 골든래빗 《스프링 부트 3 백엔드 개발자 되기 - 자바 편》의 04장 써머리입니다.
package me.allchan.springbootdeveloper;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
public class JUnitLifecycleTest {
public JUnitLifecycleTest() {
System.out.println("new JUnitLifecycleTest");
}
@BeforeEach
void setUp() {
System.out.println("setUp");
}
@Test
void testA() {
System.out.println("test A");
}
@Test
void testB() {
System.out.println("test B");
}
@AfterEach
void tearDown() {
System.out.println("tearDown");
System.out.println();
}
}
new JUnitLifecycleTest
setUp
test A
tearDown
new JUnitLifecycleTest
setUp
test B
tearDown
assertThat(articleResponseDto.getTitle()).isEqualTo(createArticleRequestDto.getTitle());
https://stackabuse.com/guide-to-unit-testing-spring-boot-rest-apis/