Junit Runner类无法找到步骤定义文件

时间:2016-04-27 06:42:00

标签: java cucumber cucumber-junit cucumber-java

JUnit Runner类无法找到具有项目结构的Steps定义文件。 的的src /测试/ JAVA / COM / testSteps / TestSteps.java 和JunitRunner类下 的的src /测试/ JAVA / COM / cucumbertestrunner / TestRunner的

[(Project Hierarchy is attached Below)以下是JUnitRunner类的语法

package com.cucumbertestrunner;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;  
@RunWith(Cucumber.class)
@CucumberOptions(features ={"src/test/resources/TestSteps.feature"},
glue ={"src/test/java/com"},strict = true,plugin = {"pretty", "html:target/cucumber"})
public class TestRunner {

}

以JUnit Test运行TestRunner.java会显示以下异常:

at cucumber.api.PendingException:TODO:在cucumber.runtime.junit.JUnitReporter.addFailure(JUnitReporter.java:134)实现我          cucumber.runtime.junit.JUnitReporter.addFailureOrIgnoreStep(JUnitReporter.java:122)         在cucumber.runtime.junit.JUnitReporter.result(JUnitReporter.java:91)         在cucumber.runtime.Runtime.runStep(Runtime.java:281)         在cucumber.runtime.model.StepContainer.runStep(StepContainer.java:44)         在cucumber.runtime.model.StepContainer.runSteps(StepContainer.java:39)         在cucumber.runtime.model.CucumberScenario.run(CucumberScenario.java:44)         在cucumber.runtime.junit.ExecutionUnitRunner.run(ExecutionUnitRunner.java:91)         在cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:63)         在cucumber.runtime.junit.FeatureRunner.runChild(FeatureRunner.java:18)         在org.junit.runners.ParentRunner $ 3.run(ParentRunner.java:238)         在org.junit.runners.ParentRunner $ 1.schedule(ParentRunner.java:63)         在org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)         在org.junit.runners.ParentRunner.access $ 000(ParentRunner.java:53)         在org.junit.runners.ParentRunner $ 2.evaluate(ParentRunner.java:229)         在org.junit.runners.ParentRunner.run(ParentRunner.java:309)         在cucumber.runtime.junit.FeatureRunner.run(FeatureRunner.java:70)

请帮助。

1 个答案:

答案 0 :(得分:1)

请查看TestSteps类,以及步骤方法包含的内容。抛出PendingException是这些步骤的默认实现。你必须实际执行该步骤应该做的事情。

除此之外,我建议将步骤的位置设置为包,因为步骤是在类中定义的,而且必须位于类路径中。

例如

 glue = {"com.teststeps"}

我还建议引用类路径中的功能文件,因为它们位于资源文件夹

features = {"classpath:TestSteps.feature}