-
[Test Code] @NotBlank 테스트 코드 작성 방법Spring 2023. 7. 3. 00:12
검사하고 싶은 Entity
@Getter @Embeddable @NoArgsConstructor public class NotificationContent { @NotBlank(message = "notification content must not be blank") @Column(nullable = false) private String content; public NotificationContent(String content) { this.content = content; } }
@NotBlank test code
@SpringBootTest class NotificationContentTest { private Validator validator = null; @BeforeEach public void setupValidator() { validator = Validation.buildDefaultValidatorFactory().getValidator(); } @Test public void 알림_내용_공백시_실패() throws Exception { //given NotificationContent content = new NotificationContent(" "); //when Set<ConstraintViolation<NotificationContent>> violations = validator.validate(content); //then assertThat(violations.size()).isEqualTo(1); } }
'Spring' 카테고리의 다른 글
[Spring Security] kakao 소셜 로그인 (0) 2023.11.21 Event Publisher / Event Listener (0) 2023.07.04 SecurityConfig - SecurityFilterChain (0) 2022.11.13 [Querydsl] BooleanBuilder과 BooleanExpression (0) 2022.08.26 Spring 개념 (0) 2022.08.08