Maven不执行任何单元测试 [英] Maven doesn't execute any unit test
问题描述
我正在将Maven与多模块一起使用.有3个项目.
I am using Maven with multi-modules. There are 3 projects.
foo(the parent project)
foo-core
foo-bar
我在foo
的pom中配置所有依赖项和插件:
I configure all the dependencies and plugins in foo
's pom:
<modules>
<module>../foo-core</module>
<module>../foo-bar</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
...
</dependency>
</dependencies>
</dependencyManagement>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.14.1</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.14.1</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</pluginManagement>
</build>
foo-core
中有几个用于单元测试的基类和util类,因此我在foo-core
项目中添加了maven-jar-plugin
,以使其可用于foo-bar
:
There are several base classes and util classes for unit test in foo-core
, so I add the maven-jar-plugin
in foo-core
project to make it available to foo-bar
:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
执行test
目标时,得到的结果如下:
When I execute test
goal, I got the result as follow:
-------------------------------------------------------
T E S T S
-------------------------------------------------------
parallel='none', perCoreThreadCount=true, threadCount=2, useUnlimitedThreads=false
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
我的项目中确实有测试.但是为什么它不运行任何一个呢?
I do got tests in my projects. But why it doesn't run any of them?
推荐答案
将测试文件从**Tests.java
重命名为**Test.java
或将以下配置添加到pom.xml
Rename test files from **Tests.java
to **Test.java
or add the following configuration to pom.xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.14.1</version>
<configuration>
<includes>
<include>**/*Tests.java</include>
</includes>
</configuration>
</plugin>
这篇关于Maven不执行任何单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!