使用 testNG Maven 从 info.cukes 更改为 io.cucumber

我有一个使用 maven 的硒黄瓜 testng 框架。我希望在使用 testng 运行黄瓜测试时获得步骤描述。这是一个旧项目,所以我已将我的依赖项从 info.cukes 更改为最新版本的 io.cucumber。但是,每当我运行运行程序测试文件时,它似乎都会抛出错误。


java.lang.NoSuchMethodError: cucumber.runtime.RuntimeOptions.getPluginFormatterNames()Ljava/util/List;


    at cucumber.runtime.formatter.Plugins.createPlugins(Plugins.java:64)

    at cucumber.runtime.formatter.Plugins.<init>(Plugins.java:37)

    at cucumber.api.testng.TestNGCucumberRunner.<init>(TestNGCucumberRunner.java:56)

    at cucumber.api.testng.AbstractTestNGCucumberTests.setUpClass(AbstractTestNGCucumberTests.java:16)

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

    at java.lang.reflect.Method.invoke(Method.java:498)

    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)

    at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:59)

    at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:458)

    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:222)

    at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:142)

    at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:168)

    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:105)

    at org.testng.TestRunner.privateRun(TestRunner.java:648)

    at org.testng.TestRunner.run(TestRunner.java:505)

    at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)

    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)

    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)

    at org.testng.SuiteRunner.run(SuiteRunner.java:364)

我有以下 maven 依赖项,但不知道它是否是我运行测试所缺少的依赖项?任何帮助将不胜感激。当我搜索这个问题时,它似乎主要是通过对我所做的所有 io.cucumber 文件具有相同版本的依赖关系来解决的。


阿波罗的战车
浏览 233回答 2
2回答

拉莫斯之舞

检查 maven pom.xml 黄瓜-核心黄瓜-java 黄瓜-junit这些文件应该具有相同的版本。在您的示例中,cucumber-java artifact id 的版本与其他版本不同。尝试改变它。

函数式编程

在下面找到一些片段来分解问题检查是否存在对 groupid的传递依赖info.cukes$ mvn dependency:tree | grep 'info.cuke'[INFO] |&nbsp; +- info.cukes:cucumber-junit:jar:1.2.5:compile[INFO] |&nbsp; |&nbsp; \- info.cukes:cucumber-core:jar:1.2.5:compile[INFO] |&nbsp; |&nbsp; &nbsp; &nbsp;+- info.cukes:cucumber-html:jar:0.2.3:compile[INFO] |&nbsp; |&nbsp; &nbsp; &nbsp;\- info.cukes:cucumber-jvm-deps:jar:1.0.5:compile[INFO] |&nbsp; +- info.cukes:cucumber-testng:jar:1.2.5:compile[INFO]&nbsp; &nbsp; |&nbsp; +- info.cukes:cucumber-java:jar:1.2.5:compile[INFO]&nbsp; &nbsp; |&nbsp; +- info.cukes:gherkin:jar:2.12.2:compile检查完整输出时会显示您的哪个依赖项取决于它...[INFO] +- com.github.mkolisnyk:cucumber-report-generator:jar:1.3:compile...[INFO] |&nbsp; +- info.cukes:cucumber-junit:jar:1.2.5:compile...[INFO] |&nbsp; +- info.cukes:cucumber-testng:jar:1.2.5:compile...[INFO] \- ru.sbtqa.tag:cucumber-runner:jar:1.0.7:compile[INFO] \- ru.sbtqa.tag:cucumber-runner:jar:1.0.7:compile[INFO]&nbsp; &nbsp; +- ru.yandex.qatools.allure:allure-cucumber-jvm-adaptor:jar:1.6.4:compile...[INFO]&nbsp; &nbsp; |&nbsp; +- info.cukes:cucumber-core:jar:1.2.5:compile...[INFO]&nbsp; &nbsp; |&nbsp; +- info.cukes:cucumber-java:jar:1.2.5:compile[INFO]&nbsp; &nbsp; |&nbsp; +- info.cukes:gherkin:jar:2.12.2:compile...[INFO]&nbsp; &nbsp; +- info.cukes:cucumber-junit:jar:1.2.5:compile由于可能存在具有相同限定名称的类的重叠,因此在 pom.xml&nbsp; &nbsp; <dependency>&nbsp; &nbsp; &nbsp; &nbsp; <groupId>com.github.mkolisnyk</groupId>&nbsp; &nbsp; &nbsp; &nbsp; <artifactId>cucumber-report-generator</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; <version>1.3</version>&nbsp; &nbsp; &nbsp; &nbsp; <exclusions>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <exclusion>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <groupId>info.cukes</groupId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <artifactId>*</artifactId>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </exclusion>&nbsp; &nbsp; &nbsp; &nbsp; </exclusions>&nbsp; &nbsp; </dependency>再次运行测试会抛出异常java.lang.NoClassDefFoundError: gherkin/IGherkinDialectProvider当我们明确定义io.cucumber:gherkin它可能与指定的依赖项时,将<version>其注释掉以查看是否获取了另一个版本<!--<dependency>-->&nbsp; &nbsp; <!--<groupId>io.cucumber</groupId>-->&nbsp; &nbsp; <!--<artifactId>gherkin</artifactId>-->&nbsp; &nbsp; <!--<version>6.0.14</version>--><!--</dependency>-->这表明,io.cucumber:cucumber-core:jar:4.2.0取决于版本5.1.0的io.cucumber:gherkin$ mvn dependency:tree...[INFO] +- io.cucumber:cucumber-core:jar:4.2.0:compile[INFO] |&nbsp; +- io.cucumber:cucumber-html:jar:0.2.7:compile[INFO] |&nbsp; +- io.cucumber:gherkin:jar:5.1.0:compile通过这些更改,至少TestNG单元测试正在运行。作为依赖项com.github.mkolisnyk:cucumber-report-generator,ru.sbtqa.tag:cucumber-runner根据info.cuke依赖项,它们可能不再正常工作。要解决此类问题,您可以:检查可能不依赖于组 ID 的较新版本&nbsp;info.cuke使用早期版本的io.cucumber依赖项使用更细粒度的info.cuke依赖项排除,而不是排除所有工件 ID以上几点的组合其他东西,取决于您的用例和要求也许这些步骤可以帮助您找到适合您的解决方案。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java