用黄瓜运行JUnit测试后出现NoSuchMethodError [英] NoSuchMethodError after run JUnit test with Cucumber

查看:144
本文介绍了用黄瓜运行JUnit测试后出现NoSuchMethodError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Intellij IDEA IDE. 我在项目中编写了2个Java类和1个功能黄瓜文件.特征结构是:

I'm using Intellij IDEA IDE. I wrote 2 java classes and 1 feature cucumber file in project. feature structure is:

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类:

Also I wrote 1 jUnit java class for RunTest with Cucumber.class:

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班级的签名,其中包含黄瓜的授课时间,然后:

And this is signature of my Test class with cucumber's given, when and then:

   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,则会捕获到此异常:

But if I try run jUnit Test, I catched this exception:

java.lang.NoSuchMethodError:gherkin.formatter.model.Scenario.getId()Ljava/lang/String;

java.lang.NoSuchMethodError: gherkin.formatter.model.Scenario.getId()Ljava/lang/String;

我不知道我在什么原因下看到此异常. 我也在异常之前看到了这一点:

And I don't know in which reasons I see this exception. Also I see this before exception:

0个场景

0 Scenarios

0步

0m0.000s

如我所知,如果我将数组作为字符串进行字符串输入,则Ljava/lang/String会che.但是在这段代码中,我没有数组.

As I know, Ljava/lang/String cheked if I string arrays as strings. But in this code I haven't arrays.

更新.

因此,我找到了此异常的原因. 需要使用小黄瓜2.12.2.

So, I find reason for this exception. Need to use gherkin 2.12.2.

推荐答案

在您在java.lang.NoSuchMethodError上面提供的异常中:gherkin.formatter.model.Scenario.getId()Ljava/lang/String;

In the Exception you provided above java.lang.NoSuchMethodError: gherkin.formatter.model.Scenario.getId()Ljava/lang/String;

我认为您正在使用的gherkin 2.12.0.jar在指定的类中没有getId函数

i think you are using gherkin 2.12.0.jar which does not have getId function in the specified class

请使用gherkin 2.12.2.jar并将此jar放置在您的项目构建路径中,然后尝试执行

Please use gherkin 2.12.2.jar and place this jar in your project build path and try executing

这篇关于用黄瓜运行JUnit测试后出现NoSuchMethodError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆