有人可以建议我一个解决方案,为什么当我使用命令
mvn test
运行测试来运行位于 ExampleRunnerTest
中的黄瓜运行器类 \src\test\java
时,它会运行,但 Maven 构建无法识别它。就像我说的,测试运行做了它应该做的事情,但构建仍然失败。
1 Scenarios (←[32m1 passed←[0m)
6 Steps (←[32m6 passed←[0m)
1m36.764s
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 98.777 sec - in BasicTest
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
@RunWith(Cucumber.class)
@CucumberOptions(features = "src/main/java/cucumber/feature/Basic.feature", glue = "cucumber/stepDefinition",
format = {"pretty", "html:target/cucumber", "json:target/cucumber-report.json"})
public class BasicTest {
}
当我在 Selenium 项目中遇到这个问题时,我意识到我也在使用 junit 和 TestNG。我从 pom.xml 中删除了 TestNG 代码和依赖项。这样我的项目中就只剩下junit了。然后一切都很顺利,MVN 测试结果显示了正确的数字。
复制品-
Rai Gupta is right.
The dependency was an issue for me also.
I saw too many "Append your runner class with Test, move the runner class into TEST folder" etc.
但是你只是破坏了整个设计,最终会导致不同设计的框架。
JUnit and SureFire plugin need to be aligned. I used
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
AND
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
However, this came in with a parallel execution problem. I did not need it, removed. But you can try different versions of the above dependency.
最后,这对我有用:测试没有通过 Maven 运行?
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.3.2</version>
</dependency>
这可能是 Surefire 库中 jUnit 支持的问题。我按照此链接解决了该问题。
有效! 为什么您的 JUnit 5 测试没有在 Maven 下运行
我通过在最新版本中显式添加以下插件来使用 JUnit 5 修复了此问题:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.1.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.1.2</version>
</plugin>
</plugins>
</build>
2.x 版本不起作用。