1

I want to implement the following scenario. Starting with a list of arguments passed into a first test in my class that should run in parallel, i then want to switch to sequential behavior for very single argument passed to the first test. Given the following code:

public class TrickyTestExecutionOrder {

  @Test
    @ArgumentsSource(CustomArgumentProvider.class)
    public void firstParallelForEachNumber(String number) {
        ...
    }

    @Nested
    public class ForEveryArgumentProceededInFirstTestMethod {

        @Test
        public void thenDoThis() {
            ...
        }

        @Test
        public void andDoThat() {
          ...
        }

        @Test
        public void andFinallyThisAgain() {
            ...
        }
   }
}

There is no must using the ArgumentsProvider as parameter provider. @MethodSource or ParameterResolver are other options to fulfill requirements. But, currently i am using an arguments provider class:

public static class CustomArgumentProvider implements ArgumentsProvider {

        @Override
        public Stream<? extends Arguments> provideArguments(ExtensionContext context) throws Exception {
            return Stream.of(
                    Arguments.of("12345"),
                    Arguments.of("67890")
            );
        }
    }

The execution path should be as follows:

                                              Thread-1   Thread-2

firstParallelForEachNumber:                   "12345"    "67890"
                                                 |           |
                                                 |           |
ForEveryArgumentProceededInFirstTestMethod :  thenDoThis  thenDoThis
                                                 |           |
                                             andDoThat     andDoThat
                                                 |           |
                                     andFinallyThisAgain  andFinallyThisAgain                               

Is this possible with JUnit5?

Bernado
  • 548
  • 1
  • 6
  • 18

0 Answers0