如何解决使用JUNIT5运行黄瓜功能文件时无法过滤它们
我可以同时运行Cucumber + JUnit5 + Gradle组合的Cucumber功能文件。但是无法过滤需要运行的功能文件;
我的功能文件位于资源文件夹下的路径“ com.automation.runners”下。并且,@ Cucumber类也位于包名称中,但位于java文件夹下; 通过这种配置,我可以运行所有功能文件,但是我只想运行一个功能文件。
我在“ junit-platform.properties”中有一个条目cucumber.features = com / automation / runners / Demo.feature。但是此解决方案不适用于我。请帮帮我!
解决方法
如果您查看documentation for the Cucumber Junit 5 integration,则会发现cucumber.features
未列为受支持的属性之一。如果您阅读了Java doc on @Cucumber:
* Some build tools do not support the
* {@link org.junit.platform.engine.discovery.DiscoverySelectors} used by
* Cucumber. As a work around Cucumber will scan the package of the annotated
* class for feature files and execute them.
因此,可以预期您的所有功能都将执行。
要运行单个功能,可以将Console Launcher与--select-file
或JUnit Platform Launcher API一起使用。两者都可以使用the supported selectors。
package com.example;
import org.junit.platform.engine.discovery.DiscoverySelectors;
import org.junit.platform.launcher.Launcher;
import org.junit.platform.launcher.LauncherDiscoveryRequest;
import org.junit.platform.launcher.core.LauncherDiscoveryRequestBuilder;
import org.junit.platform.launcher.core.LauncherFactory;
public class RunSingleFile {
public static void main(String... args) {
Launcher launcher = LauncherFactory.create();
LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request()
.selectors(DiscoverySelectors.selectFile("path/to/my.feature"))
.build();
launcher.execute(request);
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。