@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);
// then
assertThat(result1).isFalse();
assertThat(result2).isTrue();
assertThat(result3).isTrue();
}
- 3가지 given(상황)을 줘서 결과 값 전부를 테스트해보고 싶을 때
@DisplayName("상품 타입이 재고 관련 타입인지를 체크한다.")
@CsvSource({"HANDMADE,false", "BOTTLE,true", "BAKERY,true"})
@ParameterizedTest
void containsStockType4(ProductType productType, boolean expected) {
// when
boolean result = ProductType.containsStockType(productType);
// then
assertThat(result).isEqualTo(expected);
}
private static Stream<Arguments> providerProductTypesForCheckingStockType() {
return Stream.of(
Arguments.of(HANDMADE, false),
Arguments.of(BOTTLE, true),
Arguments.of(BAKERY, true)
);
}
@DisplayName("상품 타입이 재고 관련 타입인지를 체크한다.")
@MethodSource("providerProductTypesForCheckingStockType")
@ParameterizedTest
void containsStockType5(ProductType productType, boolean expected) {
// when
boolean result = ProductType.containsStockType(productType);
// then
assertThat(result).isEqualTo(expected);
}
https://junit.org/junit5/docs/current/user-guide/#writing-tests-parameterized-tests
JUnit 5 User Guide
Although the JUnit Jupiter programming model and extension model do not support JUnit 4 features such as Rules and Runners natively, it is not expected that source code maintainers will need to update all of their existing tests, test extensions, and custo
junit.org
https://spockframework.org/spock/docs/2.3/data_driven_testing.html#data-tables
Data Driven Testing
Like with data pipes, you can also assign to multiple variables in one expression, if you have some object Groovy can iterate over. Unlike with data pipes, the syntax here is identical to standard Groovy multi-assignment syntax: @Shared sql = Sql.newInstan
spockframework.org
'Spring관련 기술 > 테스트코드' 카테고리의 다른 글
테스트코드의 장점 (0) | 2024.01.23 |
---|---|
Rest docs 참고 사이트 (1) | 2023.12.31 |
한 눈에 들어오는 Test Fixture 구성하기 (0) | 2023.12.25 |
BDD Mockito (0) | 2023.12.24 |
@Mock, @Spy, @InjectMocks (0) | 2023.12.24 |