CLI runner cucumber.api.cli.Main 找不到步骤定义
CLI runner cucumber.api.cli.Main cannot find step definitions
问题
Cucumber 在 运行 使用 CLI 运行ner 时找不到步骤定义,但在 运行 junit 运行ner 时可以找到它。
也就是说,当从 linux 命令行 运行ning cucumber-jvm 时,找到了特征文件,但是没有找到步骤定义文件,产生了消息,
"Undefined scenarios: src/test/java/com/logic/testing/ClassifyDocuments.feature:8"
(完整消息见底部)
但是,运行通过 Maven,例如'mvn test',已找到步骤定义并且测试按预期执行。我已经回顾了类似的令人作呕的问题,并希望在我秃顶之前得到任何帮助。
- 文件是否需要以不同方式组织,例如使用 'resources' 目录?
- 胶水参数 com.logic.testing 不正确吗?
- class路径有问题吗?
详情
这是在 '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
com.logic.testing
StepDefinitions.java
ClassifyDocuments.feature
src/main/java
com.logic.testing
AutoTestController.java(包含 StepDefinitions.java 引用的 class)
target/test-classes/com/logic/testing/
StepDefinitions.class
target/classes/com/logic/testing/
AutoTestController.class
在 /usr/local/bin/cucumber/ 内是:
cucumber-core-1.2.5.jar
黄瓜-java-1.2.5.jar
黄瓜-jvm-deps-1.05.jar
小黄瓜-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();
}
Cucumber 扫描 class 路径寻找胶水。
所以乍一看我会说你的-cp
是错误的。当从 auto-test
执行时,我希望它包括 ./target/classes/
及其后代而不是 .
.
我已经将 cucumber-core.jar 下载到 c:\cukes 文件夹中,我的测试 classes 在 target/test-classes 文件夹中,因为我正在使用 maven。我的 Maven 依赖项也在我的配置文件的 .m2 文件夹中。下面的命令行代码对我来说很好。
java -cp "c:/cukes/*;./../../.m2/*;target/test-classes" cucumber.api.cli.Main --glue "stepdefinitions" src/test/resources/features/sample.feature
我猜,您遇到的问题可能是因为 class 路径,请尝试以下操作
java -cp "/usr/local/bin/cucumber/*;target/test-classes;target/classes" cucumber.api.cli.Main -g "com.logic.testing" src/test/java/com/logic/testing/
也许你的 cucumber-java 和 cucumber-junit 版本旧了?更新依赖关系帮助我解决了这个问题。然后重新加载项目。
问题
Cucumber 在 运行 使用 CLI 运行ner 时找不到步骤定义,但在 运行 junit 运行ner 时可以找到它。
也就是说,当从 linux 命令行 运行ning cucumber-jvm 时,找到了特征文件,但是没有找到步骤定义文件,产生了消息,"Undefined scenarios: src/test/java/com/logic/testing/ClassifyDocuments.feature:8"
(完整消息见底部)
但是,运行通过 Maven,例如'mvn test',已找到步骤定义并且测试按预期执行。我已经回顾了类似的令人作呕的问题,并希望在我秃顶之前得到任何帮助。
- 文件是否需要以不同方式组织,例如使用 'resources' 目录?
- 胶水参数 com.logic.testing 不正确吗?
- class路径有问题吗?
详情
这是在 '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
com.logic.testing
StepDefinitions.java
ClassifyDocuments.feature
src/main/java
com.logic.testing
AutoTestController.java(包含 StepDefinitions.java 引用的 class)
target/test-classes/com/logic/testing/
StepDefinitions.class
target/classes/com/logic/testing/
AutoTestController.class
在 /usr/local/bin/cucumber/ 内是:
cucumber-core-1.2.5.jar
黄瓜-java-1.2.5.jar
黄瓜-jvm-deps-1.05.jar
小黄瓜-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();
}
Cucumber 扫描 class 路径寻找胶水。
所以乍一看我会说你的-cp
是错误的。当从 auto-test
执行时,我希望它包括 ./target/classes/
及其后代而不是 .
.
我已经将 cucumber-core.jar 下载到 c:\cukes 文件夹中,我的测试 classes 在 target/test-classes 文件夹中,因为我正在使用 maven。我的 Maven 依赖项也在我的配置文件的 .m2 文件夹中。下面的命令行代码对我来说很好。
java -cp "c:/cukes/*;./../../.m2/*;target/test-classes" cucumber.api.cli.Main --glue "stepdefinitions" src/test/resources/features/sample.feature
我猜,您遇到的问题可能是因为 class 路径,请尝试以下操作
java -cp "/usr/local/bin/cucumber/*;target/test-classes;target/classes" cucumber.api.cli.Main -g "com.logic.testing" src/test/java/com/logic/testing/
也许你的 cucumber-java 和 cucumber-junit 版本旧了?更新依赖关系帮助我解决了这个问题。然后重新加载项目。