0

I have a Maven project setup. In the project, am using JUnit in for unit testing. When I run tests with mvn test or mvn clean test, no tests are run. Tests are in src/test/java and they all end in Test (they match *Test.java).

This is my pom.xml:

<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>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.7.0</version>
                <configuration>
                    <source>1.9</source>
                    <target>1.9</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-api</artifactId>
            <version>5.0.3</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-params</artifactId>
            <version>5.1.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.1</version>
        </dependency>
    </dependencies>

    <groupId>org.astropeci.ppp4e</groupId>
    <artifactId>ppp4e</artifactId>
    <version>1.0</version>
</project>

My entire project structure can be seen here: https://bitbucket.org/equator-lang/ppp4e/src/master/

Any help would be greatly appreciated as I have been trying for many hours to get this to work and have no idea what to do.

EDIT:

After making a test class public, the Maven response changed from:

-------------------------------------------------------
 T E S T S
-------------------------------------------------------

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

To:

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running org.astropeci.ppp4e.defaultimpl.internal.lexing.MultiplexedTokenBuilderTest
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.002 sec

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
Llew Vallis
  • 337
  • 4
  • 12

1 Answers1

4

JUnit 5 support is not yet built into the maven-surefire-plugin that is responsible for running your unit tests. You need to configure the plugin with a provider in order for it to work.

I use the following configuration:

<properties>
    ...
    <maven-surefire-plugin.version>2.20.1</maven-surefire-plugin.version>
    <junit-5.version>5.2.0</junit-5.version>
</properties>

...
    <plugin>
      <artifactId>maven-surefire-plugin</artifactId>
      <version>${maven-surefire-plugin.version}</version>
      <!-- JUnit 5 Support -->
      <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>${junit-5.version}</version>
        </dependency>
      </dependencies>
    </plugin>
 ...

  <dependency>
    <groupId>org.junit.jupiter</groupId>
    <artifactId>junit-jupiter-api</artifactId>
    <version>${junit-5.version}</version>
    <scope>test</scope>
  </dependency>
...
Steve C
  • 18,876
  • 5
  • 34
  • 37
  • My build is now failing because the params extension is not found. When adding a dependency the params extension as I had it in my original pom, Maven says 'build.plugins.plugin[org.apache.maven.plugins:maven-surefire-plugin].dependencies.dependency.scope' for org.junit.jupiter:junit-jupiter-params:jar must be one of [compile, runtime, system] but is 'test'. – Llew Vallis Jun 20 '18 at 09:28
  • After changing the surefire dependency from test to compile it works. Thanks a million. – Llew Vallis Jun 20 '18 at 09:41
  • surefire dependency? that does not sound right. Most JUnit 5 components seem to be tightly coupled at this time. Make sure you choose a matching set – Steve C Jun 20 '18 at 09:45
  • Yes, the very first entry (under ) is the one that was problematic. Also, I don't know what a matching set is and I can't find anything from Google. – Llew Vallis Jun 20 '18 at 09:57
  • You need maven-surefire-plugin version 2.20.1 (or newer I guess) with junit-platform-surefire-provider 1.2.0. (that's a matching set). And then you need the junit-jupiter-api and junit-jupiter-params versions to match the junit-jupiter-engine version - that's another matching set. For the latter I parameterise them in maven properties as you can see. – Steve C Jun 20 '18 at 10:34
  • 1
    I strongly recommend to use maven-surefire 2.22.0....see the https://blogs.apache.org/maven/entry/apache-maven-surefire-plugin-2 or http://blog.soebes.de/blog/2018/06/16/apache-maven-surefire-plugin-version-2-dot-22-released/ – khmarbaise Jun 20 '18 at 10:40