当前位置: 首页 > 知识库问答 >
问题:

CLI运行程序cucumber.api.CLI.main找不到步骤定义

翁阳曜
2023-03-14

问题
Cucumber在使用CLI运行程序运行时找不到步骤定义,但在使用junit运行程序运行时可以找到。

也就是说,当从linux命令行运行cucumber-jvm时,找到了特性文件,但未找到步骤定义文件,从而生成消息
“未定义的场景:src/test/java/com/logic/testing/classifydocuments.feature:8”
(完整消息请参阅底部)

但是,通过Maven(例如'mvn test')运行时,会找到步骤定义,并按预期执行测试。我已经复习过类似的问题了,在我秃顶之前,我会很感激你的帮助。
-是否需要对文件进行不同的组织,例如使用“resources”目录?
-胶水参数com.logic.testing是否不正确?
-类路径有问题吗?

详细信息
下面是在“auto-test”文件夹中发出的命令行语句:
java-cp“/usr/local/bin/cucumber/cucumber-core-1.2.5.jar:/usr/local/bin/cucumber/*:”cucumber.api.cli.main-g com.logic.testing src/test/java/com/logic/testing/classifydocuments.feature-s

代码的组织方式如下:
自动测试/
  src/test/java
       StepDefinitions.java
    ClassifyDocuments.Feature
  src/main/java
    AutoTestController.java(包含一个由StepDefinitions.java引用的类)
  Target/test-classs/com/logic/testing/
    StepDefinitions.class
   

在/usr/local/bin/cucumber/is中:
cucumber-core-1.2.5.jar
cucumber-java-1.2.5.jar
cucumber-jvm-deps-1.05.jar
gherkin-2.12.2.jar

ClassifyDocuments.Feature文件:

Feature: Classify documents in a package
  As an auditor
  I want to use software
  So that I don't have to manually identify subdocuments

Scenario: execute workflow case2 test
Given the workflow case2 test can be configured
And I have been authenticated
When two jobs are submitted with different SLA duration
And the jobs are processed
Then the packages with the shorter SLA duration are completed first

stepdefinitions.java文件:

package com.logic.testing;

import java.io.File;

import org.junit.Assert;

import cucumber.api.java.en.And;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;

public class StepDefinitions {

    AutoTestController  atc;
@Given("^the workflow case2 test can be configured$")
    public void the_workflow_case2_test_can_be_configured() throws Throwable {
        atc = new AutoTestController();
        atc.log("~Looking for configuration", log_src);
        Assert.assertTrue(atc.getAutoTestConfig("workflow_case2"));
    }

    @When("^two jobs are submitted with different SLA duration$")
    public void two_jobs_are_submitted_with_different_SLA_duration() throws Throwable {
        Assert.assertTrue(atc.two_jobs_are_submitted_with_different_SLA_duration());
    }

    @And("^the jobs are processed$")
    public void the_jobs_are_processed() throws Throwable {
        Assert.assertTrue(atc.processJobs());
    }

    @Then("^the packages with the shorter SLA duration are completed first$")
    public void the_packages_with_the_shorter_SLA_duration_are_completed_first() throws Throwable {
        Assert.assertTrue(atc.checkPackageCompletionTimes("QC_CLASSIFICATION", "READY", 10, 300));
    }
}

执行命令行语句后返回错误(是,它确实以“uuuuu”开头):

UUUUU

Undefined scenarios:
src/test/java/com/logic/testing/ClassifyDocuments.feature:8 # Scenario: execute workflow case2 test

1 Scenarios (1 undefined)
5 Steps (5 undefined)
0m0.000s


You can implement missing steps with the snippets below:

@Given("^the workflow case(\\d+) test can be configured$")
public void the_workflow_case_test_can_be_configured(int arg1) throws Throwable {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@Given("^I have been authenticated$")
public void i_have_been_authenticated() throws Throwable {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@When("^two jobs are submitted with different SLA duration$")
public void two_jobs_are_submitted_with_different_SLA_duration() throws Throwable {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@When("^the jobs are processed$")
public void the_jobs_are_processed() throws Throwable {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@Then("^the packages with the shorter SLA duration are completed first$")
public void the_packages_with_the_shorter_SLA_duration_are_completed_first() throws Throwable {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

共有1个答案

宗翔宇
2023-03-14

Cucumber扫描类路径中的胶水。

所以看一眼,我会说您的-cp是错误的。从auto-test执行时,我希望它包括./target/classes/及其后代,而不是.

 类似资料:
  • 测试步骤: 我试过“abc”,“^abc”,“give abc”...在@gived上 我用下面的bat文件和步骤定义来驱动它,并且类文件就在那里。在-g(glue)选项中,我意识到包名是参数值,所以我尽可能简单地实现了这一点,但我只找到了0个场景。bat文件很简单: 如果*.feature文件是cucumber运行的必要条件,并且即使junit被挂到cucumber.class测试运行程序中,它

  • 在如下定义的项目结构中, src/main/java--Config(RunCukesTest.java)--步骤定义 当我使用RunAs从

  • 我遇到了以下问题。我在Intellij中有四个Cucumber特性文件。我通过IntelliJ插件添加了Cucumber支持。在创建了特性之后,我按如下所示编辑了配置,这样我就可以执行特性文件了。 可悲的是,当我尝试使用步骤定义运行cucumber特性时,我得到的提示是“您可以使用下面的代码片段实现缺少的步骤:”但我已经这样做了。我已经将这些片段复制到步骤定义文件中。当我悬停一个场景时,Intel

  • 本文向大家介绍jboss( WildFly)上运行 springboot程序的步骤详解,包括了jboss( WildFly)上运行 springboot程序的步骤详解的使用技巧和注意事项,需要的朋友参考一下 WildFly,原名 JBoss AS(JBoss Application Server) 或者 JBoss,是一套应用程序服务器,属于开源的企业级 Java 中间件软件,用于实现基于 SOA

  • cucumber runner类似乎找不到步骤定义类,但它可以找到功能文件。 功能文件: 步骤定义类: 跑步者等级: 作为JUnit测试运行Runner类的输出: 我只是将输出复制并粘贴到我的步骤定义类中,它仍然无法识别步骤定义类。早些时候,它说场景中的每一步都没有匹配的粘合代码,但是在我关闭并重新打开功能文件后,这种情况就消失了。