Practical Testing: 실용적인 테스트 가이드

@ParameterizedTest @DisplayName("상품 타입이 재고 관련 타입인지를 체크한다.") @Test void containsStockType3() { // given ProductType givenType1 = HANDMADE; ProductType givenType2 = BOTTLE; ProductType givenType3 = BAKERY; // when boolean result1 = ProductType.containsStockType(givenType1); boolean result2 = ProductType.containsStockType(givenType2); boolean result3 = ProductType.containsStockType(givenType3); // ..
한 눈에 들어오는 Test Fixture 구성하기 Test Fixture Fixture: 고정물, 고정되어 있는 물체 테스트를 위해 원하는 상태로 고정시킨 일련의 객체 테스트 코드를 작성하다 보면 (BeforeEach, BeforeAll) @DisplayName("신규 상품을 등록한다. 상품번호는 가장 최근 상품의 상품번호에서 1증가한 값이다.") @Test void createProduct() { // given Product product1 = createProduct("001", BAKERY, SELLING, "아메리카노", 4000); } 이런 코드를 중복적으로 작성하게 된다. 그래서 이런 방법을 생각해볼 수 있다. @BeforeAll static void beforeAll() { // befor..
BDD Mockito 기존 Mockito @DisplayName("메일 전송 테스트") @Test void sendMail() { // given Mockito.when(mailSendClient.sendEmail(anyString(), anyString(), anyString(), anyString())) .thenReturn(true); // when /* */ // then /* */ } 어 이상하다. given에 when이 있네? @DisplayName("메일 전송 테스트") @Test void sendMail() { // given BDDMockito.given(mailSendClient.sendEmail(anyString(), anyString(), anyString(), anyString()..
@Mock MockBean이라는 것은 Spring Context가 작동되어야 수행할 수 있다. 스프링을 쓰지 않고 순수 자바 (단위테스트)에서도 Mock 개념을 사용해야할 수 있다.! class MailServiceTest { @DisplayName("메일 전송 테스트") @Test void sendMail() { // given MailSendClient mailSendClient = mock(MailSendClient.class); MailSendHistoryRepository mailSendHistoryRepository = mock(MailSendHistoryRepository.class); MailService mailService = new MailService(mailSendClient, m..
https://martinfowler.com/articles/mocksArentStubs.html Mocks Aren't Stubs Explaining the difference between Mock Objects and Stubs (together with other forms of Test Double). Also the difference between classical and mockist styles of unit testing. martinfowler.com Dummy 아무 것도 하지 않는 깡통 객체 Fake 단순한 형태로 동일한 기능은 수행하나, 프로덕션에서 쓰기에는 부족한 객체(ex. FakeRepository) Stub 테스트에서 요청한 것에 대해 미리 준비한 결과를 제공하는 객체 그 ..
요구사항 추가 관리자가 특정일자를 입력하면, 그 날짜에 해당하는 하루치 매출 통계를 메일로 전송해주는 서비스 예) 2023.12.24일 입력하면 2023.12.24일 00:00:00 ~ 12:59:59 이하에 해당하는 매출 통계를 메일로 전송한다. 구현코드 https://github.com/beginner0107/cafekiosk/commit/8f16e2f387560124257c24c5e92caf2be2d3002c Mockito로 Stubbing하기 - 예제) Mail 전송 기능 테스트 하는 법 · beginner0107/cafekiosk@8f16e2f beginner0107 committed Dec 24, 2023 github.com @RequiredArgsConstructor @Service publ..
솜사탕코튼
'Practical Testing: 실용적인 테스트 가이드' 태그의 글 목록