java - 如何在 cucumber 中重新运行失败的方案

标签 java gradle intellij-idea automated-tests cucumber

我在我们的项目中使用Cucumbe编写自动化测试,并在Gradle依赖项(例如Junit)中编写插件。
但是,某些情况下会失败,主要是由于超时原因,然后重新运行它们将是一个永久性的解决方案。

我尝试了以下代码:

Run our test classes
@RunWith(CustomCucumber.class)
@CucumberOptions(
        junit = "--filename-compatible-names",
        features = "src/test/resources/features",
        glue = {"stepdefinition", "main", "hooks"},
        tags = {"@MyScenario", "@5"},
        plugin = {
                "pretty",
                "json:target/cucumber-reports/CucumberTestReport.json",
                "com.github.kirlionik.cucumberallure.AllureReporter",
                "html:target/cucumber-repoIrts/cucumber-pretty",
                "com.cucumber.listener.ExtentCucumberFormatter:",
                "rerun:target/rerun.txt"
        }
)

public class RunTest { }

重新运行失败的方案:
@RunWith(CustomCucumber.class)
@CucumberOptions(
        junit = "--filename-compatible-names",
        features = "@target/rerun.txt",
        glue = {"stepdefinition", "main", "hooks"},
        plugin = {
                "pretty",
                "json:target1/cucumber-reports/CucumberTestReport.json",
                "com.github.kirlionik.cucumberallure.AllureReporter",
                "junit:target1/cumcumber.xml",
                "html:target1/cucumber-repoIrts/cucumber-pretty",
                "com.cucumber.listener.ExtentCucumberFormatter:",
        }
)
public class RunTestRerun {
}

我看到文件已在目标文件夹中生成,但是当我尝试运行rerun.txt时会引发异常:
java.lang.IllegalArgumentException: Neither found on file system or on classpath: Not a file or directory: C:/mytest/Signup/Client/Client.feature, No resource found for: classpath:Signup/Client/Client.feature
    at cucumber.runtime.model.CucumberFeature.loadFromFileSystemOrClasspath(CucumberFeature.java:84)
    at cucumber.runtime.model.CucumberFeature.loadFromRerunFile(CucumberFeature.java:67)
    at cucumber.runtime.model.CucumberFeature.load(CucumberFeature.java:52)
    at cucumber.runtime.model.CucumberFeature.load(CucumberFeature.java:34)
    at cucumber.runtime.RuntimeOptions.cucumberFeatures(RuntimeOptions.java:239)
    at runner.CustomCucumber.CustomCucumber.<init>(CustomCucumber.java:68)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
    at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
    at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
    at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:49)
    at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
    at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
    at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)

[SETUP ERROR] Neither found on file system or on classpath: Not a file or directory: C:/mytest/Signup/Client/Client.feature, No resource found for: classpath:Signup/Client/Client.feature

Rerun.txt
Signup/Client/Client.feature:30

关于我将如何解决的任何想法?

最佳答案

在Eclipse中运行失败的测试用例时,我遇到了类似的问题。我将类路径指向了项目文件中我的功能文件所在的文件夹。您可以按照以下步骤操作:

1)右键单击Project并转到Run Configuration

2)点击类路径

3)在“用户条目”下选择您的项目,然后单击“高级”

4)点击添加文件夹

5)然后选择项目文件所在的文件夹,然后单击“应用”。
尝试重新运行失败的运行程序,它应在此之后运行。如果再次进入类路径,则会在失败的运行者可以引用的用户条目下找到添加的类路径。

关于java - 如何在 cucumber 中重新运行失败的方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62452335/

相关文章:

java - 日期JSON解析形式

android - 错误 : Permissions not granted. .. react-native-image-picker

android-studio - 无法在空对象上调用方法 systemProperty() -- android studio 和 gradle

intellij-idea - Intellij 13.0.2 始终处于领先地位

java - IntelliJ VCS ui 问题如何解决?

python - IntelliJ IDEA : Python plugin does not highlight Python code

java - 与 MacBook Pro 上的 64 位 Eclipse 不兼容的 JVM 错误消息

java - 使用本地数据库进行java应用程序

java - 如何检查文件是否处于锁定模式?

maven - 401 Unauthorized 从 GitHub Packages 使用 Gradle 下载公共(public)包