【发布时间】:2012-02-09 05:46:30
【问题描述】:
当我的 pom 设置为打包类型“pom”时,我在运行单元测试时遇到了一些问题。起初,它说这个项目不需要目标,所以我将 maven-surefire-plugin 添加到我的 pom.xml 以将测试阶段绑定到 maven-surefire-plugin 测试目标。
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.9</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
现在,surefire 插件正在执行,但它说没有要运行的测试。如果我将打包类型更改为 jar 并运行 mvn test,那么它会获取我的测试文件。
当我运行 mvn test -X 时,它显示“testSourceDirectory = C:\dev\dsl\src\test\java”,这是正确的位置。包装类型“pom”与“jar”的测试位置是否不同?我尝试添加
<configuration>
<testSourceDirectory>src/test/java</testSourceDirectory>
</configuration>
到万无一失的插件,但它根本没有帮助。
【问题讨论】:
-
Pom 打包仅用于元数据项目,不是吗?你想做什么?
-
我实际上处于同样的场景中——我有一个系统测试模块,我只想运行它,但不想从中生成一个 jar。但是,如果不实际指定 pom 之外的其他东西的包装类型,我就无法运行测试。我该怎么做(这可能值得一个单独的问题)。
-
@DaveNewton 我想这样做是因为它不是 Java 应用程序,我想生成一个带有数据库脚本的 zip 文件作为工件。
-
@whaley 如下所示,您需要将 compiler:testCompile 目标绑定到测试编译阶段,并将 surefire:test 目标绑定到测试阶段。
标签: maven junit pom.xml maven-surefire-plugin