Unit testing the parametrized test programmatically with out Suite

Viewed 47

I do have some parametrized test and i want to run the tests programmatically and not with annotation processors e.g @Suite @RunWith(Suite.class) , is there a way that i can access and invoke the test classes from other test classes ?

  • Some test cases
@SpringBootTest
class Test {

    @ParameterizedTest
    @ValueSource(strings = {"first", "second"})
    public void example(String values) {
    ...
    }
    
   ...
}
2 Answers

You can use EngineTestKit that provides support for executing a test plan for a given TestEngine and then accessing the results via a fluent API to verify the expected results.

EngineTestKit
            .engine("junit-jupiter")
            .selectors(selectClass(Test.class))
            .execute().testEvents().assertStatistics(o -> o.failed(1));
Related