java - CucumberOptions 不运行功能
问题描述
在 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>
任何帮助都会非常感激。谢谢 :)
解决方案
嗯,这是一个艰难的。我不太确定为什么要为“step”、“hooks”、“helpers”等类指定粘合路径。粘合路径定义了找到 stepDefinitions 的包。这是我的一个项目中的一个例子:
@RunWith(Cucumber.class)
@CucumberOptions( monochrome = true,
tags = "@tags",
features = "src/test/resources/",
format = { "pretty","html: cucumber-html-reports",
"json: cucumber-html-reports/cucumber.json" },
dryRun = false,
glue = "stepMethods" )
stepMethods 是我的步骤定义所在的包。也许只是尝试这样做(在您的场景中):
glue = "codelab"
祝你好运 :)
推荐阅读
- typo3 - PersistenceManager 不会持久化 TYPO3 中的最后一个条目
- python - 如何正确保留图像尺寸
- include - 为什么创建和删除用例之间没有包含链接
- c++ - Kubuntu:在 GDB 中调试 C++ 应用程序会使应用程序的音频静音
- javascript - 来自输入字段在 React/Javascript/Bootstrap 中不会自动调整大小
- flutter-web - Flutter Web:不使用 dart:io 裁剪图像
- node.js - docker-compose 用于将 VS Code 中的 node.js 调试器附加到 WSL docker 中的节点进程
- html - 通过嵌入代码在网站上循环播放 Youtube 视频
- powerbi - 在 Films 表中创建一个名为 NumberBreaks 的计算列,它显示每部电影所需的休息次数
- react-native - 将示例从 PIXIJS 转换为 Expo-PIXI