[JBoss] Junit5 Wildfly TestEngine implementation is found via Class.forName but not found...

Discussão em 'StackOverflow' iniciado por Stack, Março 20, 2025.

  1. Stack

    Stack Membro Participativo

    I have a war deployed on wildfly that depends on a module where Junit5 jars are located. I keep getting this exception

    [Cannot create Launcher without at least one TestEngine; consider adding an engine implementation JAR to the classpath]: org.junit.platform.commons.PreconditionViolationException: Cannot create Launcher without at least one TestEngine; consider adding an engine implementation JAR to the classpath


    The code that I'm using for testing this is

    @RestController
    @RequestMapping("/Paolo")
    public class HelloController {
    Logger logger = LoggerFactory.getLogger(HelloController.class);
    @GetMapping("/hello")
    String hello() throws ClassNotFoundException {
    Class.forName("org.junit.jupiter.engine.JupiterTestEngine"); // no exception thrown
    Iterable<TestEngine> testEngines = ServiceLoader.load(TestEngine.class,
    ClassLoaderUtils.getDefaultClassLoader()); // method used by junit to found the TestEngineImplementation JupiterTestEngine is the only real implementation
    logger.info("testEngines: {}", testEngines.iterator().hasNext()); // false
    }
    }


    If instead of having Junit5 jars in the module I put them in the WEB-INF/lib of the war everything works just fine.

    I understood form here that modlues are loaded and putted in the classpath of the war.

    Why if I move the jars under WEB-INF/lib it works which is the difference?

    You can find the complete example here the correct branch is junit5

    Continue reading...

Compartilhe esta Página