(JUnit5 기준 작성)
자주 사용하는 assert 관련 method
- assertTure
- assertFalse
- assertEquals
- assertNotEquals
- assertThrowsExactly
- assertInstanceOf
assertThrowsExactly example
assertThrows(ExpectedException.class, () -> Method to test);
다른 bean과 의존 관계 있는 경우 Mock 사용
class ServiceTest {
private AutoCloseable openMocks;
private Service service;
@Mock
private OtherService otherService;
@BeforeEach
void setUp() {
openMocks = MockitoAnnotations.openMocks(this);
service = new Serivce(otherService);
}
@AfterEach
void tearDown() throws Exception {
openMocks.close();
}
@Test
void test() {
}
}
댓글