Maven找不到测试

时间:2018-06-20 08:53:17

标签: java maven

我有一个Maven项目设置。在项目中,正在使用JUnit进行单元测试。当我使用mvn testmvn clean test运行测试时,不会运行任何测试。测试在src/test/java中进行,并且都在Test中结束(它们与*Test.java相匹配)。

这是我的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>

我的整个项目结构可以在这里看到:https://bitbucket.org/equator-lang/ppp4e/src/master/

任何帮助都将不胜感激,因为我一直在努力使它正常工作并且不知道该怎么办。

编辑:

公开测试类后,Maven响应从以下更改:

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

Results :

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

收件人:

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

1 个答案:

答案 0 :(得分:2)

负责运行单元测试的maven-surefire-plugin尚未内置JUnit 5支持。您需要使用提供程序配置插件才能使其正常工作。

我使用以下配置:

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