Java Intellij IDEA中测试步骤的Cumber PendingExcepion
我问了一个关于黄瓜和爪哇的问题。 在更正我的项目后,我检查了cucumber junit中的PendingException。我有两个类:TestClass.java用于使用SoapUI,TestSteps.java用于使用代码实现步骤,JUnit Run.java类。 这是我的代码: TestClass.java:Java Intellij IDEA中测试步骤的Cumber PendingExcepion,java,intellij-idea,cucumber,cucumber-jvm,cucumber-junit,Java,Intellij Idea,Cucumber,Cucumber Jvm,Cucumber Junit,我问了一个关于黄瓜和爪哇的问题。 在更正我的项目后,我检查了cucumber junit中的PendingException。我有两个类:TestClass.java用于使用SoapUI,TestSteps.java用于使用代码实现步骤,JUnit Run.java类。 这是我的代码: TestClass.java: public class FirstTest { private static String xmlFile; private static String projectP
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";
}
}
这是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();
}
}
黄瓜特征:
Scenario: Test
Given I have a file "path_to_file"
Then I want to run case
和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 {
}
如果我尝试运行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$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.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$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.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)
但我只是在java文件中实现了这些步骤。往哪个方向看?为什么我可以检查此异常?
更新:
在Eclipse中也尝试一下这段代码,它不起作用。
有人知道原因吗?
UPD2:编辑描述
UPD 3:重新创建项目帮助删除
抛出新的PendingException()代码>来自您的步骤。您在代码中显式抛出异常
删除下面的行:
throw new PendingException();
Java中的throw
关键字用于显式地从方法或任何代码块抛出异常。我们可以抛出选中或未选中的异常
throw
关键字主要用于抛出自定义异常
抛出异常的语法示例:抛出新的算术异常(“/by zero”)代码>默认模板中确实应该有一个文本,上面写着“在执行步骤时删除此项”,因为不清楚抛出的目的是什么。