Java 如何在Cucumber中重新运行失败的场景

Java 如何在Cucumber中重新运行失败的场景,java,gradle,intellij-idea,automated-tests,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/resource

我在我们的项目中使用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 {
}
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时,它会引发异常:

@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 {
}
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

有没有想过如何解决这个问题?

在eclipse中运行失败的测试用例时,我遇到了类似的问题。我将类路径指向项目中的功能文件所在的文件夹。您可以按照以下步骤操作:
1) 右键单击Project并转到运行配置
2) 单击类路径
3) 在“用户条目”下选择您的项目,然后单击“高级”
4) 单击添加文件夹
5) 然后选择项目中要素文件所在的文件夹,然后单击“应用”


尝试重新运行失败的运行程序,它应在此之后运行。如果您再次转到类路径,那么您将在失败的运行程序可以引用的用户条目下找到添加的类路径。

在eclipse中运行失败的测试用例时,我遇到了类似的问题。我将类路径指向项目中的功能文件所在的文件夹。您可以按照以下步骤操作:
1) 右键单击Project并转到运行配置
2) 单击类路径
3) 在“用户条目”下选择您的项目,然后单击“高级”
4) 单击添加文件夹
5) 然后选择项目中要素文件所在的文件夹,然后单击“应用”

尝试重新运行失败的运行程序,它应在此之后运行。如果再次转到类路径,则会在失败的运行程序可以引用的用户条目下找到添加的类路径