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

특정 데이터를 포함하는 샘플링을 할 수 있을까요? #1064

Open
im-gnar opened this issue Oct 18, 2024 · 1 comment
Open

특정 데이터를 포함하는 샘플링을 할 수 있을까요? #1064

im-gnar opened this issue Oct 18, 2024 · 1 comment
Labels
question Further information is requested

Comments

@im-gnar
Copy link
Contributor

im-gnar commented Oct 18, 2024

안녕하세요.
우선 좋은 라이브러리 제공에 감사드립니다.

테스트를 작성하는 과정에서 특정 데이터가 포함된 경우를 테스트해야하는 케이스가 있는데,
매번 for 문을 돌리며 set을 하고 추가로 필요한 사이즈만큼 샘플링을 해 합치는 작업이 반복되어 문의드립니다.

// size = 3
requiredIds.stream()
           .map(id -> fixture.giveMeBuilder(SomeObject.class)
                             .set("id", id) 
                             .sample())
           .toList();
fixture.giveMe(SomeObject.class, 7);

아래처럼 필수적으로 포함되었으면 하는 파라미터를 전달하면 전달 파라미터를 우선 설정하고, 남은 size 만큼에 대해서는 기존처럼 랜덤 샘플링해주는 옵션을 제공하고 있을까요?
혹 제공하지 않는다면 특별한 이유가 있는지 문의드립니다.

fixture.giveMeBuilder(SomeObject.class)
       .set("id", requiredIds)  // requiredIds.size() = 3
       .sampleList(10);
@im-gnar im-gnar added the question Further information is requested label Oct 18, 2024
@seongahjo
Copy link
Contributor

@im-gnar 님 안녕하세요.

Fixture Monkey에서 제공하는 ArbitraryBuilder의 set 연산의 마지막 파라미터로 integer를 입력받고 있습니다.
이 파라미터로 연산을 실행할 횟수를 정할 수 있습니다.

다음과 같이 설정하면 set 연산을 3개의 인스턴스에 적용 가능합니다.

Iterator<String> expected = List.of("1", "2", "3").iterator();
List<String> actual = SUT.giveMeBuilder(String.class)
	.setLazy("$", () -> expected.next(), 3)
	.sampleList(5);
// "1", "2", "3", ...

위 같이 사용하면 원하시는대로 설정이 가능할 것 같습니다.
혹시 안되시면 다시 말씀해주세요.

감사합니다.

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