Here is classical example of the JUnit 5 data-driven test.
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit.jupiter.SpringExtension;
@Slf4j
@ExtendWith(SpringExtension.class)
@SpringBootTest
class ScrathTest {
@Autowired
private MyBean myBean;
@ParameterizedTest
@ValueSource(ints = {1, 3, 5, -3, 15, Integer.MAX_VALUE}) // six numbers
void isOdd_ShouldReturnTrueForOddNumbers(int number) {
myBean.doSomeThing(number)
}
}
But what if I need to run this not for integer array, but profiles array? I mean I create a single test, and 3 test profiles then repeat this test 3 times with different profiles in each innovation. Is it possible?
Note
@ActiveProfile annotation is not a solution because it simply activates listed profiles without test repeating and context recreation.