1

I'm facing problems when running a Test Suite of JUnit 5 Jupiter with Spring.

I'm using latest version of Spring (5.2.8-RELEASE) (not spring-boot) and latest version of JUnit Jupiter (5.7.0).

Here is my Test Suite code:

package mypackage.test;

import org.junit.jupiter.api.MethodOrderer.OrderAnnotation;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.TestInstance.Lifecycle;
import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.platform.suite.api.SelectPackages;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.context.web.AnnotationConfigWebContextLoader;
import org.springframework.test.context.web.WebAppConfiguration;

@WebAppConfiguration
@ExtendWith(SpringExtension.class)
@ContextConfiguration(loader = AnnotationConfigWebContextLoader.class, classes = {
        MyRootSpringConfiguration.class })
@SelectPackages("mypackage.test.units")
class MyTestSuite {

}

This way, I'm loading the context of the application, and then I want to execute all the corresponding tests.

But it seems not working, as Eclipse doesn't recognize this Class as JUnit 5 Test Class.

I have a similar configuration for the individual Test Classes, and they work fine. But each file loads the context, and that's not a good solution. I prefer to have a Suite that loads the context once, and then all the Tests uses this context to be executed.

Any idea about how to configure it?

Marc Gil Sendra
  • 819
  • 2
  • 9
  • 22
  • SelectPackages is not what you think it is. It only works in combination with JUnit 4 and RunWith(JUnitPlatform.class). Moreover, SpringExtension is designed for individual test classes; there’s no working way to use it for a whole suite or package. – johanneslink Oct 02 '20 at 05:20
  • Sure that it's not possible with JUnit 5 and Spring to create a Suite Test? It sounds very very strange... – Marc Gil Sendra Oct 05 '20 at 08:35
  • Jupiter creates suites by class, package, folder, classpath. But there's currently no way for a programmatic combination of individual tests. Instead you can use tags and filter a test run by those. – johanneslink Oct 05 '20 at 12:41

0 Answers0