Maven找不到测试 [英] Maven doesn't find tests
问题描述
我有一个Maven项目设置.在项目中,我正在使用JUnit进行单元测试.当我使用mvn test
或mvn clean test
运行测试时,不会运行任何测试.测试在src/test/java
中进行,所有测试均在Test
中结束(它们与*Test.java
匹配).
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
).
这是我的pom.xml:
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>
我的整个项目结构可以在这里看到: https://bitbucket.org /equator-lang/ppp4e/src/master/
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.
将测试类公开后,Maven响应从以下更改:
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
收件人:
-------------------------------------------------------
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
推荐答案
负责运行单元测试的maven-surefire-plugin尚未内置JUnit 5支持.您需要使用提供程序配置插件才能使其正常工作.
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.
我使用以下配置:
<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>
...
这篇关于Maven找不到测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!