给定文件夹结构:
theProject/src/com/myclass/tests/api/APITest
其中包声明为:
package com.myclass.tests.api;
它使用了来自testng的@Test。
在pom.xml中,我包含了build部分:
<build>
<testSourceDirectory>${project.basedir}/</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<includes>
<include>**/*Test.class</include>
<include>**/*test.class</include>
<include>src/com/myclass/tests/api/*Test.class</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
我尝试在pom.xml所在的theProject文件夹中执行以下命令。
mvn test -Dtest=com.myclass.tests.api.*
但结果显示:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test (default-test) on project theProject: No tests were executed! (Set -DfailIfNoTests=false to ignore this error.) -> [Help 1]
我应该如何从mvn运行测试?
发布于 2018-08-22 06:08:22
我不认为
<testSourceDirectory>${project.basedir}/</testSourceDirectory>
那就是你想要的。
试一试
<testSourceDirectory>${project.basedir}/src</testSourceDirectory>
而不是。
推理: Maven找不到文件夹结构
/com/myclass/tests/api
这可能是${project.basedir}
中的包结构(您的测试)的结果,因此它找不到您的测试并失败。额外的src文件夹需要进行寻址。
https://stackoverflow.com/questions/51960519
复制相似问题