我在一个项目中工作,我实现了一个简单的功能、stepdefinition 类和运行器,并想使用 testJUnit 或在我运行 TestNG.xml 时对其进行测试。
但是我有这个问题
You can implement missing steps with the snippets below:
@Given("^sample feature file is ready$")
public void sample_feature_file_is_ready() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
@When("^I run the feature file$")
public void i_run_the_feature_file() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
@Then("^run should be successful$")
public void run_should_be_successful() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new PendingException();
}
我的特点是:
@smokeTest
Feature: To test my cucumber test is running
I want to run a sample feature file.
Scenario: cucumber setup
Given sample feature file is ready
When I run the feature file
Then run should be successful
我的步骤定义是:
public class Test_Steps {
@Given("^sample feature file is ready$")
public void givenStatment(){
System.out.println("Given statement executed successfully");
}
@When("^I run the feature file$")
public void whenStatement(){
System.out.println("When statement execueted successfully");
}
@Then("^run should be successful$")
public void thenStatment(){
System.out.println("Then statement executed successfully");
}
我的运行者是:
@RunWith(Cucumber.class)
@CucumberOptions(
features = {"D:\\feat\\user"},
glue={"stepsdef"},
tags= "@smokeTest")
public class RunnerTestInChrome extends AbstractTestNGCucumberTests {
}
我怎么知道stepdefinition类和我的特征相关! 我不明白我执行方法脚本的问题
最佳答案
这意味着 Cucumber 无法找到您的胶水代码(步骤定义)。
对于胶水而不是 glue={"stepsdef"},
提供到 stepsdef
的路径。
顺便说一句,建议将您的功能文件放在 src/test/resources :)
如果您无法让它工作,请尝试 cucumber-java-skeleton ;它旨在“开箱即用”,应该比设置您自己的项目更容易使用。
如果您确实想建立自己的项目,请查看此 blogpost ,它应该会指导您完成设置项目并将文件放在正确目录中的步骤...
关于java - 无法运行 TestNG 或 JUnit 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49573282/