[英]java.lang.NoSuchMethodError when run test with Junit 5
[英]NoSuchMethodError after run JUnit test with Cucumber
我正在使用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
阻塞。 但是在這段代碼中,我沒有數組。
UPDATE。
因此,我找到了此異常的原因。 需要使用小黃瓜2.12.2。
在上面提供的Exception中,java.lang.NoSuchMethodError:gherkin.formatter.model.Scenario.getId()Ljava / lang / String;
我認為您正在使用的gherkin 2.12.0.jar在指定的類中沒有getId函數
請使用gherkin 2.12.2.jar並將此jar放置在項目構建路徑中並嘗試執行
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.