【发布时间】:2021-10-14 18:08:30
【问题描述】:
在 Cucumber 中编码了几年后,我在尝试执行测试时遇到了奇怪的错误:
Exception in thread "main" java.lang.NoSuchMethodError: org.junit.runner.Description.createSuiteDescription(Ljava/lang/String;Ljava/io/Serializable;[Ljava/lang/annotation/Annotation;)Lorg/junit/runner/Description;
at io.cucumber.junit.FeatureRunner.getDescription(FeatureRunner.java:118)
at io.cucumber.junit.Cucumber.describeChild(Cucumber.java:191)
at io.cucumber.junit.Cucumber.describeChild(Cucumber.java:89)
at org.junit.runners.ParentRunner.getDescription(ParentRunner.java:290)
at com.intellij.junit4.JUnit4IdeaTestRunner.getDescription(JUnit4IdeaTestRunner.java:79)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:51)
at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)
TestRunner 类:
package codelab.runners;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import org.junit.runner.RunWith;
@RunWith(Cucumber.class)
@CucumberOptions(
glue = {"codelab.step", "codelab.page", "codelab.hooks", "codelab.helpers", "codelab.api"},
features = "src/test/resources/features/",
plugin = {"json:target/cucumber.json", "pretty"})
public class TestRunner {
}
该错误与@CucumberOptions 注解中提供的特征路径密切相关。路径是正确的,我不知道为什么它突然停止工作......
POM.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>codelab</groupId>
<artifactId>babel_guru_selenium</artifactId>
<version>1.0</version>
<properties>
<projectName>BabelGuru</projectName>
<reportInputDirectory>${project.build.directory}</reportInputDirectory>
<reportOutputDirectory>${project.build.directory}/cucumber-report-html</reportOutputDirectory>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>selenium</id>
<phase>initialize</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<file>${project.basedir}/src/test/resources/lib/JARs/SeleniumHelper.jar</file>
<groupId>codelab</groupId>
<artifactId>SeleniumHelper</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<pomFile>D:/projects/quality_assurance/Engines/SeleniumHelper/pom.xml</pomFile>
</configuration>
</execution>
<execution>
<id>webdriver</id>
<phase>initialize</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<file>${project.basedir}/src/test/resources/lib/JARs/WebDriverFactory.jar</file>
<groupId>codelab</groupId>
<artifactId>WebDriverFactory</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<pomFile>D:/projects/quality_assurance/Engines/WebDriverFactory/pom.xml</pomFile>
</configuration>
</execution>
<execution>
<id>restAssured</id>
<phase>initialize</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<file>${project.basedir}/src/test/resources/lib/JARs/RestAssuredEngine.jar</file>
<groupId>codelab</groupId>
<artifactId>RestAssuredHelper</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<pomFile>D:/projects/quality_assurance/Engines/RestAssuredHelper/pom.xml</pomFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<filtering>true</filtering>
<directory>./src/main/resources/profiles/${build.profile.id}</directory>
</resource>
</resources>
</build>
<dependencies>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.8</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
</dependency>
<dependency>
<groupId>codelab</groupId>
<artifactId>RestAssuredHelper</artifactId>
<version>1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>codelab</groupId>
<artifactId>SeleniumHelper</artifactId>
<version>1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>codelab</groupId>
<artifactId>WebDriverFactory</artifactId>
<version>1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>7.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>7.0.0</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>7.0.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>[4.10]</version>
<scope>test</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<id>local</id>
<properties>
<build.profile.id>local</build.profile.id>
</properties>
</profile>
<profile>
<id>dev</id>
<properties>
<build.profile.id>dev</build.profile.id>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>test</id>
<properties>
<build.profile.id>test</build.profile.id>
</properties>
</profile>
</profiles>
</project>
任何帮助都会非常感激。谢谢:)
【问题讨论】:
-
支持那个 Junit 版本吗?
-
严格使用4.10版本,没有更新。
-
而黄瓜究竟找不到哪种方法?
-
一个,你可以在堆栈跟踪中看到。现在我注意到,如果我有一个空的功能文件,例如带有注释掉的场景,TestRunner 可以访问它。当然它不会运行任何东西,但也不会抛出异常。有一个场景再次抛出异常......
-
所以您已经告诉您的构建系统使用非常特定版本的 JUnit。你让 Cucumber 抱怨它找不到 JUnit 方法。你可能想把这些点联系起来。
标签: java selenium junit cucumber