我正在使用 Intellij IDEA IDE。 我在项目中编写了2个java类和1个功能 cucumber 文件。特征结构为:
Feature: First test
with Cucumber
Scenario: Testing
Given file.xml from ext
When take project path
Then run test
我还用 Cucumber.class 为 RunTest 编写了 1 个 jUnit java 类:
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;
import org.hamcrest.SelfDescribing;
import gherkin.util.FixJava;
import cucumber.deps.com.thoughtworks.xstream.converters.ConverterRegistry;
@RunWith(Cucumber.class)
public class RunTest {
}
这是我的测试类的签名,其中包含 cucumber 的给定时间和时间:
public class CallSoapSteps {
//variables for file and path to project
String fileXML = "";
String pathToProj = "";
//take any xml file for insert it into Insert() SoapUI step
@Given("^file.xml from ext$")
public String file_xml_from_ext()
{
//take file
return fileXML = "path_to_xml_file";
}
//any statement about our xml file
@When("^take project path$")
public String take_project_path()
{
//take path to project
return pathToProj = "path_to_soap_project";
}
//any properties for our steps and running SoapTest
@Then("^run test$")
public void run_test() throws Exception {
//add test project
WsdlProject project = new WsdlProject(take_project_path());
//add xml file for test into property
project.setPropertyValue("File", file_xml_from_ext());
//get TestSuite and TestCase by name
TestSuite testSuite = project.getTestSuiteByName("Test");
TestCase testCase = testSuite.getTestCaseByName("Test");
//run test
testCase.run(new PropertiesMap(), false);
}
}
但是如果我尝试运行 jUnit Test,我捕获了此异常:
java.lang.NoSuchMethodError: gherkin.formatter.model.Scenario.getId()Ljava/lang/String;
而且我不知道我看到这个异常的原因是什么。 我还在异常之前看到了这一点:
0 Scenarios
0 Steps
0m0.000s
据我所知,Ljava/lang/String
检查我是否将数组作为字符串。但在这段代码中我没有数组。
更新。
所以,我找到了这个异常的原因。 需要使用小 cucumber 2.12.2。
最佳答案
在上面提供的异常 java.lang.NoSuchMethodError: gherkin.formatter.model.Scenario.getId()Ljava/lang/String;
我认为您使用的是 gherkin 2.12.0.jar,它在指定的类中没有 getId 函数
请使用 gherkin 2.12.2.jar 并将此 jar 放在您的项目构建路径中并尝试执行
关于java - 使用 Cucumber 运行 JUnit 测试后出现 NoSuchMethodError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28807402/