【发布时间】:2013-05-23 07:27:59
【问题描述】:
我正在使用带有多模块的 Maven。有3个项目。
foo(the parent project)
foo-core
foo-bar
我在foo的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 中有几个用于单元测试的基类和实用程序类,所以我在foo-core 项目中添加了maven-jar-plugin 以使其对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 目标时,我得到如下结果:
-------------------------------------------------------
T E S T S
-------------------------------------------------------
parallel='none', perCoreThreadCount=true, threadCount=2, useUnlimitedThreads=false
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
我确实在我的项目中进行了测试。但为什么它不运行其中的任何一个?
【问题讨论】:
-
测试文件的名称是否与 Surefire 页面上列出的一致? maven.apache.org/surefire/maven-surefire-plugin/examples/…
-
@Grzegorz 是的。所有测试文件都命名为 ***Tests.java。
-
如果有请看答案。
标签: unit-testing maven maven-surefire-plugin