15

当我的 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>

到surefire插件,但它根本没有帮助。

4

1 回答 1

16

正如 Dave 所说,如果您使用pom打包,它只会执行以下生命周期目标。请参阅相关的 Maven 文档。

  • 包裹
  • 安装
  • 部署

如果您需要它来运行任何其他目标,则需要明确指定它。例如,

mvn clean compiler:testCompile surefire:test
于 2012-01-13T04:16:25.593 回答