-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Description
Hi,
I have a class with a couple of parametrized tests (testA, testB). I want to execute the parameters of each test in parallel, but I don't want to execute all the tests at one time. From looking at the documentation, I found we could use @Order annotation. But the order is not being respected - it is concurrently executing both methods instead of doing one method parallel at a time.
MRP:
@TestMethodOrder(MethodOrderer.OrderAnnotation::class)
class ParallelTest {
@Order(1)
@ParameterizedTest
@ValueSource(strings = ["a", "b", "c"])
@Execution(ExecutionMode.CONCURRENT)
fun testA(input: String) {
println("First test with $input")
Thread.sleep(1000)
}
@Order(2)
@ParameterizedTest
@ValueSource(strings = ["a", "b", "c"])
@Execution(ExecutionMode.CONCURRENT)
fun testB(input: String) {
println("Second test with $input")
Thread.sleep(1000)
}
}
In this example both methods run with input at random order in my IntelliJ output. What I would want is 'First test with input a', b, c, then 'Second test with a', b, c, etc. Also, the order annotation is not working - if I swap the order annotation of both functions it does nothing.
I was able to get what I want somewhat working like this:
@TestMethodOrder(MethodOrderer.OrderAnnotation::class)
class ParallelTest {
@Nested
inner class FirstTest {
@ParameterizedTest
@ValueSource(strings = ["a", "b", "c"])
@Execution(ExecutionMode.CONCURRENT)
fun testA(input: String) {
println("First test with $input")
Thread.sleep(1000)
}
}
@Nested
inner class SecondTest {
@ParameterizedTest
@ValueSource(strings = ["a", "b", "c"])
@Execution(ExecutionMode.CONCURRENT)
fun testB(input: String) {
println("Second test with $input")
Thread.sleep(1000)
}
}
}
In this situation, it executes testA in parallel, then moves on to testB. However, the Order annotation doesn't work here either - it seems like it's going off alphabetical order? Even if I add @Order(1) to SecondTest and @Order(2) to FirstTest, it still does FirstTest first. Is the nested solution the only way to get the order I want, and can we not specify the order in this situation? I'm using junit-jupiter-api » 5.9.2.