java 用于 Intellij IDEA 中测试步骤的 Cucumber PendingExceprion

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28824469/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 14:14:38  来源:igfitidea点击:

Cucumber PendingExceprion for test steps in Intellij IDEA

javaintellij-ideacucumbercucumber-jvmcucumber-junit

提问by Giymose

Erly I asked thisquestion about cucumber and java. After correct my project, I checked PendingException in cucumber-junit. I have 2 classes: TestClass.java for working with SoapUI, TestSteps.java for implementation cucumber steps with my code and JUnit Run.java class. This is my code: TestClass.java:

Erly 我问了 这个关于黄瓜和 java 的问题。纠正我的项目后,我检查了 Cucumber-junit 中的 PendingException。我有 2 个类:TestClass.java 用于使用 SoapUI,TestSteps.java 用于使用我的代码和 JUnit Run.java 类实现黄瓜步骤。这是我的代码:TestClass.java:

    public class FirstTest {
private static String xmlFile;
private static String projectPath;

public FirstTest(String file)
{
    xmlFile = file;
}
//for Then step
public static void run() throws XmlException, IOException, SoapUIException {
    //add test project
    WsdlProject project = new WsdlProject(getProjectPath());
    //add xml file for test into property
    project.setPropertyValue("File", xmlFile);
    //get TestSuite and TestCase by name
    TestSuite testSuite = project.getTestSuiteByName("Test");
    TestCase testCase = testSuite.getTestCaseByName("Test");
    //run test
    testCase.run(new PropertiesMap(), false);

}

public static String getProjectPath()
{
    return projectPath = "path";
}

}

}

And this is TestSteps.java class:

这是 TestSteps.java 类:

    public class TestSteps {
private FirstTest testClass;

@Given("^I have a file \"(.*?)\"$")
public void i_have_a_file(String file) throws Throwable {
    testClass = new FirstTest(file);
    throw new PendingException();
}

@Then("^I want to run case$")
public void i_want_to_run_case() throws Throwable {
    testClass.run();
    throw new PendingException();
}

}

}

Cucumber feature:

黄瓜特点:

    Scenario: Test
Given I have a file "path_to_file"
Then I want to run case

And JUnit Class:

和 JUnit 类:

    @RunWith(Cucumber.class)
@CucumberOptions(format = {"junit:target_junit/cucumber.xml"},
glue = {"src/com.teststeps.TestSteps"},
features = {"Feature"},
dryRun = true,
strict = true,
tags = {},
monochrome = true)

public class RunTest {
}

If I try run JUnit Class, I checking PendingException:

如果我尝试运行 JUnit 类,我会检查 PendingException:

cucumber.api.PendingException: TODO: implement me
    at cucumber.runtime.junit.JUnitReporter.addFailure(JUnitReporter.java:134)
    at cucumber.runtime.junit.JUnitReporter.addFailureOrIgnoreStep(JUnitReporter.java:122)
    at cucumber.runtime.junit.JUnitReporter.result(JUnitReporter.java:91)
    at cucumber.runtime.Runtime.runStep(Runtime.java:280)
    at cucumber.runtime.model.StepContainer.runStep(StepContainer.java:44)
    at cucumber.runtime.model.StepContainer.runSteps(StepContainer.java:39)
    at cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:48)
    at cucumber.runtime.junit.ExecutionUnitRunner.run(ExecutionUnitRunner.java:91)
    at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:63)
    at cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:18)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access##代码##0(ParentRunner.java:58)
    at org.junit.runners.ParentRunner.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at cucumber.runtime.junit.FeatureRunner.run(FeatureRunner.java:70)
    at cucumber.api.junit.Cucumber.runChild(Cucumber.java:93)
    at cucumber.api.junit.Cucumber.runChild(Cucumber.java:37)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:290)
    at org.junit.runners.ParentRunner.schedule(ParentRunner.java:71)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
    at org.junit.runners.ParentRunner.access##代码##0(ParentRunner.java:58)
    at org.junit.runners.ParentRunner.evaluate(ParentRunner.java:268)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
    at cucumber.api.junit.Cucumber.run(Cucumber.java:98)
    at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
    at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:74)
    at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:211)
    at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)

But I just implemented this steps in my java files. In what direction to look? Why can I check this exception? UPDATE: Try this code in Eclipse too, it dosen't work. Somebody know reasons? UPD 2: Edit descriptions UPD 3: Recreate project help

但我只是在我的 java 文件中实现了这些步骤。往什么方向看?为什么我可以检查这个异常?更新:也在 Eclipse 中尝试此代码,它不起作用。有人知道原因吗?UPD 2:编辑描述 UPD 3:重新创建项目帮助

回答by yole

Remove throw new PendingException();from your steps.

throw new PendingException();从你的步骤中删除。