我正在使用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 {
}
这是我的Test课程的签名,给出了黄瓜时,然后:
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。
答案 0 :(得分:3)
在上面提供的异常java.lang.NoSuchMethodError:gherkin.formatter.model.Scenario.getId()Ljava / lang / String;
我认为您正在使用gherkin 2.12.0.jar,它在指定的类中没有getId函数
请使用小黄瓜2.12.2.jar并将此jar放在项目构建路径中并尝试执行