我正在使用 Intellij IDEA IDE。我在项目中编写了 2 个 java 类和 1 个功能黄瓜文件。特征结构为:
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 {
}
这是我的测试课的签名,带有黄瓜的给定,何时:
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 场景
0 步
0m0.000s
据我所知,Ljava/lang/String
检查我是否将数组字符串作为字符串。但是在这段代码中我没有数组。
更新。
所以,我找到了这个例外的原因。需要使用小黄瓜2.12.2。