Cucumber 没有发现 JUnit5 的特性 [英] Cucumber No features found with JUnit5

查看:68
本文介绍了Cucumber 没有发现 JUnit5 的特性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的项目中设置 Cucumber.我遵循与以前的项目相同的配置,但运行测试仍然存在问题.现在我开始怀疑问题可能是这个项目使用的是 JUnit 5 而不是 4.我已将 junit4 添加到构建选项中,以便能够使用 jUnit4 执行 @RunWith 注释,但我仍然得到相同的结果错误(在类路径中未找到任何功能).runner类如下:

I am trying to setup Cucumber in my project. I am following the same configuration from my previous projects but I still have issues with running the tests. Now I am starting to suspect that the issue might be that this project is using JUnit 5 instead of 4. I have added junit4 to the build options as well to be able to execute the @RunWith annotation with jUnit4, but I still get the same error ( No features found at classpath ) . The runner class is as follows:

import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import io.cucumber.junit.CucumberOptions.SnippetType;
import org.junit.runner.RunWith;

 @RunWith(Cucumber.class)
 @CucumberOptions(features = "classpath:resources", plugin = {"pretty", "html:target/reports/cucumber/html",
"json:target/cucumber.json", "usage:target/usage.jsonx",
"junit:target/junit.xml"}, snippets = SnippetType.CAMELCASE)
public class TestCucumberRunner {

}

文件夹结构如下:

这里是 pom 配置:

Here is the pom configuration:

据我所知,@RunWith注解是从junit4而不是5导入的,那么为什么会出现这个问题呢?我还尝试在与运行器相同的文件夹中添加功能文件,以及在功能选项中添加确切路径,但仍然出现相同的错误.

As far as I can see, the @RunWith annotation is imported from junit4 and not 5, so why is this issue happening? I also tried adding the feature file in the same folder with the runner, as well as adding the exact path in the feature option, but still the same error.

推荐答案

使用Junit5,你只需要像下面这样编写runner:

With Junit5, you just need to write runner like below :

@Suite

@SelectClasspathResource(功能文件夹")公共类跑步者{

@SelectClasspathResource("Features Folder") public class Runner {

}

使用标签,可以将标签属性放在junit-platform.properties中.

For using tags, you can put the tags properties in junit-platform.properties.

您可以参考 pom 依赖项 - https://github.com/cucumber/cucumber-java-skeleton/blob/main/pom.xml

You can refer for pom dependencies - https://github.com/cucumber/cucumber-java-skeleton/blob/main/pom.xml

我遇到了很多问题.我按照上面的操作,可以使用 Junit5 运行我的黄瓜测试,没有任何问题.

I was facing a lot of issues. I followed above and could run my cucumber tests with Junit5 without any issues.

这篇关于Cucumber 没有发现 JUnit5 的特性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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