The application I am working on requires that different contexts are created depending on the JUnit tests to be run. Specifically, say I have five test classes - ClassOneTest.class, ClassTwoTest.class, ..., ClassFiveTest.class. I also use the testContainers framework to create the backend I need for testing.
I need to run ClassOneTest and ClassTwoTest with one specific context (database, config, docker container, etc, you name it). Then ClassThreeTest, ClassFourTest and ClassFiveTest with a completely different context.
The context takes a fair amount of time to be set up, so re-creating it for each test class is not an option, which implies that Context1 should be setup once, then ClassOneTest and ClassTwoTest played, then Context1 cleaned up, then Context2 created and set up, then test classes Three, Four and Five played, then Context2 cleaned up and closed. Obviously using @ExtendWith(TestExtension) on each testClass is not the way to go.
Can I possibly achieve it the way I need?