3

I am trying to run tests in a project with Apache Maven 3.8.3, JDK 14, JUnit 5.8.1, jqwik 1.5.6

I'm using IntelliJ IDEA 2021.2.3 (Community Edition)

The libraries must be correctly imported but it still doesn't work. When I try to run simple tests I 'm getting the following error message:

"Internal Error occurred. org.junit.platform.commons.JUnitException: TestEngine with ID 'junit-jupiter' failed to discover tests"

Here is the pom.xml file. I'd appreciate any advice and thanks in advance!

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>tests</groupId>
    <artifactId>tests</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    
    <build>
        <sourceDirectory>${project.basedir}/src</sourceDirectory>
        <testSourceDirectory>${project.basedir}/src/tests</testSourceDirectory>
        
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>3.0.0-M5</version>
                <configuration>
                    <includes>
                        <include>**/*Tests.java</include>
                        <include>**/*Examples.java</include>
                        <include>**/*Properties.java</include>
                    </includes>
                </configuration>
            </plugin>
        </plugins>
        
    </build>

    <dependencies>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter</artifactId>
            <version>5.8.1</version>
        </dependency>
        <dependency>
            <groupId>net.jqwik</groupId>
            <artifactId>jqwik</artifactId>
            <version>1.5.6</version>
        </dependency>

    </dependencies>
    <properties>
        <maven.compiler.source>14</maven.compiler.source>
        <maven.compiler.target>14</maven.compiler.target>
    </properties>
</project>

Yavuz Erkal
  • 31
  • 1
  • 4
  • Follow convention `${project.basedir}/src ${project.basedir}/src/tests`... – khmarbaise Nov 02 '21 at 09:17
  • Furthermore name your test accordingly instead of trying to configuration maven-surefire-pulgin... just stick with the defaults.. – khmarbaise Nov 02 '21 at 09:24
  • Apart from that you should use the dependency on the junit-jupiter-engine as documented https://maven.apache.org/surefire/maven-surefire-plugin/examples/junit-platform.html – khmarbaise Nov 02 '21 at 09:25
  • junit-jupiter-engine is not required after 5.4, see https://stackoverflow.com/a/55084036 – Alkanshel Dec 17 '21 at 02:47

1 Answers1

0

I had similar and other issues, when IntelliJ IDEA won't run unit tests, but "mvn test -pl ..." successfully runs them.

All of such issues had magically gone away after I did the following:

  1. open the "Maven" tool window in IntelliJ IDEA
  2. locate the related module with THE unit tests
  3. execute "Lifecycle | install" ("Lifecycle | test" should also work)
  4. then try again to run your unit tests - it started to work for me.

Also I disabled the "Coverage" plugin - my reasoning is that IDEA won't re-compile classes to instrument them for collection of code coverage.

Nishi
  • 10,634
  • 3
  • 27
  • 36