英文:
Unable to filter Cucumber Feature files while running them with JUNIT5
问题
我能够使用组合 cucumber+JUnit5+Gradle 并行运行 Cucumber 特性文件。但是无法筛选需要运行的特性文件;
我的特性文件位于资源文件夹下的路径 "com.automation.runners"。而且,@Cucumber 类也位于同名的包下,但在 java 文件夹下;
使用这个配置,我能够运行所有特性文件,但我想只运行一个特性文件。
在 "junit-platform.properties" 中有一个条目 cucumber.features=com/automation/runners/Demo.feature。但这个解决方案对我不起作用。请帮助我!
英文:
I'm able to run cucumber feature files in parallel with combination cucumber+JUnit5+Gradle. But unable to filter feature files which needs to be run;
My feature files are located under resource folder at path "com.automation.runners" . And, @Cucumber class is also located at the package name but under java folder;
With this configuration I am able run all feature files but I want run only one feature file.
I have an entry cucumber.features=com/automation/runners/Demo.feature in "junit-platform.properties". But this solution is not working for me. Please help me!!
答案1
得分: 1
如果您查看Cucumber Junit 5集成的文档,您会发现cucumber.features
未列为支持的属性之一。如果您阅读@Cucumber的Java文档:
* 一些构建工具不支持
* Cucumber使用的{@link org.junit.platform.engine.discovery.DiscoverySelectors}。
* 作为解决方法,Cucumber将扫描带有注释的类的包,查找功能文件并执行它们。
因此,您可以预期将执行所有功能。
要运行单个功能,您可以使用Console Launcher,并使用--select-file
选项,或者使用JUnit Platform Launcher API。对于这两者,您可以使用受支持的选择器。
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);
}
}
英文:
If you look at the documentation for the Cucumber Junit 5 integration you'll see that cucumber.features
is not listed as one of the supported properties. And if you read the 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.
So it is to be expected that all your features are executed.
To run a single feature you can use the Console Launcher with --select-file
or the JUnit Platform Launcher API. For both you can use 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);
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论