Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

시작하기 - "Bean 유효성 검사 추가하기" 동작 질문 #1017

Open
youngsu5582 opened this issue Jul 28, 2024 · 3 comments
Open

시작하기 - "Bean 유효성 검사 추가하기" 동작 질문 #1017

youngsu5582 opened this issue Jul 28, 2024 · 3 comments
Labels
question Further information is requested

Comments

@youngsu5582
Copy link

안녕하세요!
이번에 동적 테스팅 에 흥미가 생겨 학습을 하던 중
공식 문서를 따라할 때 문제점이 발생해 질문합니다.

문제점

https://naver.github.io/fixture-monkey/v1-0-0-kor/docs/get-started/adding-bean-validation/
해당 링크에서 나와있는 대로

의존성

implementation 'org.springframework.boot:spring-boot-starter-validation'
testImplementation("com.navercorp.fixturemonkey:fixture-monkey-starter:1.0.14")

lombok.config 설정
lombok.anyConstructor.addConstructorProperties=true

객체

import jakarta.validation.constraints.*;

@Value
public class ProductWithValidation {
    @Min(1)
    long id;

    @NotBlank
    String productName;

    @Max(100000)
    long price;

    @Size(min = 3)
    List<@NotBlank String> options;

    @Past
    Instant createdAt;
}

테스트 코드

@RepeatedTest(20)
void test() {
    // given
    FixtureMonkey fixtureMonkey = FixtureMonkey.builder()
            .objectIntrospector(ConstructorPropertiesArbitraryIntrospector.INSTANCE)
            .plugin(new JakartaValidationPlugin())
            .build();
    // when
    final ProductWithValidation actual = fixtureMonkey.giveMeOne(ProductWithValidation.class);

    // then
    then(actual).isNotNull();
    then(actual.getId()).isGreaterThan(0);
    then(actual.getProductName()).isNotBlank();
    then(actual.getPrice()).isLessThanOrEqualTo(100000);
    then(actual.getOptions()
            .size()).isGreaterThanOrEqualTo(3);
    then(actual.getOptions()).allSatisfy(it -> then(it).isNotEmpty());

    assertThat(actual.getCreatedAt()).isNotNull()
            .isBeforeOrEqualTo(Instant.now());
}
image

실행 시 15~17번 가량의 테스트가 실패하며

Given type class joyson.fixturemonkey.ProductWithValidation could not be generated. Check the ArbitraryIntrospector used or the APIs used in the ArbitraryBuilder.
java.lang.IllegalArgumentException: Given type class joyson.fixturemonkey.ProductWithValidation could not be generated. Check the ArbitraryIntrospector used or the APIs used in the ArbitraryBuilder.

해당 에러를 발생 시키는데 놓친 부분이 있을까요??


public record ProductWithValidation(@Min(1) long id, @NotBlank String productName, @Max(100000) long price,
                                    @Size(min = 3) List<@NotBlank String> options, @Past Instant createdAt) {
}

위와 같이 레코드로 변환시
image
테스트를 잘 통과합니다.

좋은 라이브러리 감사합니다!

@youngsu5582 youngsu5582 added the question Further information is requested label Jul 28, 2024
@seongahjo
Copy link
Contributor

@youngsu5582 님 안녕하세요.

지금 사용하고 계신 1.0.14 버전에서는 생성 시점에서 List의 개수가 고정되는 문제가 있습니다.
그래서 간헐적으로 @Min 조건을 통과하지 못하는 경우가 생기고 있어 생성이 실패합니다.
이 이슈와 동일한 문제입니다.

새로 배포할 1.0.22에서는 해당 이슈를 해결하여 배포할 예정입니다.

말씀주신대로 record에서는 이 이슈가 발생하지 않네요; 왜 이슈가 없는지는 추가적으로 확인해봐야겠네요.
공유 감사합니다!

픽스쳐몽키를 잘 사용해주셔서 감사합니다!

@seongahjo
Copy link
Contributor

@youngsu5582 님 안녕하세요. 1.0.22 버전을 배포하여 공유드립니다.

혹시 이슈가 발생한다면 말씀해주세요.

감사합니다.

@youngsu5582
Copy link
Author

확인하고 댓글 남기겠습니다!!
감사합니다. 🫡🫡

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants