Spring관련 기술/테스트코드

처음에 엔티티 이름을 Board로 지었는데 게시판은 Board지만, 게시글 하나 하나는 Post가 더 적합하다는 생각이 들었다. 그래서 Board -> Post로 바꾸기로 마음먹었는데, 보통 Test코드가 없을 때는 엄청 수작업이고, 나 혼자 할 수 없을 것이다. 50개 정도 테스트가 터지고, 문제점 확인 후 빠르게 고칠 수 있었다. 갑자기 뿌듯해서..
https://docs.spring.io/spring-restdocs/docs/current/reference/htmlsingle/#introduction Spring REST Docs Document RESTful services by combining hand-written documentation with auto-generated snippets produced with Spring MVC Test or WebTestClient. docs.spring.io 공식문서가 최고당. ㅎㅎ 근 1주일만에 프로젝트에도 적용시켜보고 재미는 있지만.. Security 인증 인가 정보 때문에 많이 시간을 허비했다. 에러 일기에 많이 작성했으니 나중에 검색해서 찾을 수 있도록! https://computerlove..
@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..
솜사탕코튼
'Spring관련 기술/테스트코드' 카테고리의 글 목록