0

I think I've tried everything in the old StackOverflow thread about this with no success.

I have a Java project with a junit jupiter test class in src/test/java, called SacmElementTest. If I run this as a JUnit test from Eclipse the tests run fine - there are 8 of them in there. But if I run the tests from Maven (within eclipse or from the command line) everything seems to be fine but I get Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, so it's not actually running the tests. My pom file is:

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>uk.co.tgrsafety</groupId>
<artifactId>gsn-editor-maven</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>gsn-editor</name>
<build>
    <sourceDirectory>src</sourceDirectory>
    <resources>
        <resource>
            <directory>src</directory>
            <excludes>
                <exclude>**/*.java</exclude>
            </excludes>
        </resource>
    </resources>

    <testSourceDirectory>src/test/java</testSourceDirectory>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.7.0</version>
            <configuration>
                <release>10</release>
            </configuration>
        </plugin>
    </plugins>
</build>
<dependencies>
    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-core</artifactId>
        <version>1.10.19</version>
    </dependency>
    <dependency>
        <groupId>org.junit.platform</groupId>
        <artifactId>junit-platform-surefire-provider</artifactId>
        <version>1.2.0-M1</version>
    </dependency>
    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <version>5.2.0-M1</version>
    </dependency>
</dependencies>
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
</project>

What am I doing wrong?

digitig
  • 1,989
  • 3
  • 25
  • 45

2 Answers2

3

Please add maven surefire plugin with correct dependency as described here for Junit 5 with Jupiter.

<plugin>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.21.0</version>
    <dependencies>
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-surefire-provider</artifactId>
            <version>1.2.0</version>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>5.2.0</version>
        </dependency>
    </dependencies>
</plugin>
Amith Kumar
  • 4,400
  • 1
  • 21
  • 28
1

Release 2.22.0 of the Surefire plugin has support for JUnit Jupiter built-in. According to its documentation you have to add the JUnit Jupiter engine to the project dependencies.

<project ...>
  ...
  <dependencies>
    ...
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-engine</artifactId>
      <version>5.2.0</version>
      <scope>test</scope>
    </dependency>
    ...
  </dependencies>
  ...
  <build>
    <plugins>
      ...
      <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.22.0</version>
      </plugin>
      ...
    </plugins>
  </build>
</project>
Stefan Birkner
  • 24,059
  • 12
  • 57
  • 72