java - 无法运行 TestNG 或 JUnit 测试

标签 java testing junit cucumber

我在一个项目中工作,我实现了一个简单的功能、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/

相关文章:

file - 检查目录中是否存在多个文件

python - 如何在测试中正确设置相对于运行脚本的路径?

junit - 将 HTML 添加到 JUnit 报告

java - Jacoco 报告显示已删除的 Java 类以进行测试覆盖

java - 它抛出 500 Failed to evaluate expression 'ROLE_USER' in spring security

java - 使用 EXIfiient 在 XML 文件中缺少 namespace 信息

java - 为什么Java中没有初始化局部变量?

java - 为什么使用 1<<4 而不是 16?

javascript - 谷歌分析即时测试器

java - 并行 JUnit 测试不执行关闭 Hook