问题
使用CLI运行程序运行时,Cucumber无法找到步骤定义,但在使用junit runner运行时可以找到它。
也就是说,当从linux命令行运行cucumber-jvm时,找到了feature文件,但找不到步骤定义文件,产生消息,"Undefined scenarios: src/test/java/com/logic/testing/ClassifyDocuments.feature:8"
(见完整信息的底部)
然而,通过Maven运行,例如'mvn test',找到步骤定义并按预期执行测试。我已经审查了类似的问题,并且在我去秃头之前会感激任何帮助。
- 文件是否需要以不同方式组织,例如使用'资源'目录?
- 胶水参数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 /测试/ JAVA
com.logic.testing
StepDefinitions.java
ClassifyDocuments.feature
的src /主/ JAVA
com.logic.testing
AutoTestController.java(包含由StepDefinitions.java引用的类)
目标/测试类/ COM /逻辑/测试/
StepDefinitions.class
目标/类/ COM /逻辑/测试/
AutoTestController.class
在/ usr / local / bin / cucumber /中:
黄瓜核心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();
}
答案 0 :(得分:1)
我已将cucumber-core.jar下载到c:\ cukes文件夹中,我的测试类位于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
我猜,你得到的问题可能是因为类路径,请尝试以下
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/
答案 1 :(得分:1)
也许您的cumul-java和cucmber-junit版本过旧?更新依赖项帮助我解决了这个问题。然后重新加载项目。
答案 2 :(得分:0)
Cucumber扫描类路径中的胶水。
所以我一眼就看出你的-cp
是错的。从auto-test
执行时,我希望它包含./target/classes/
及其后代,而不是.
。