简体   繁体   English

Cucumber-junit-platform-engine 中的特征文件发现

[英]Feature files discovery in cucumber-junit-platform-engine

In cucumber-junit library I use @CucumberOptions to define feature files location:@CucumberOptions cucumber-junit库中,我使用@CucumberOptions来定义特征文件位置:

package com.mycompany.cucumber;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
@CucumberOptions(
  plugin = ...,
  features = "classpath:.", // my java step definitions are in package com.mycompany.cucumber 
                            // but feature files directly in test resources 
                            // resources/is_it_friday_yet.feature
  tags = ...,
  glue = ...
)
public class CucumberRunner {
}

I'm running my tests with custom gradle task cucumberTest我正在使用自定义 gradle 任务cucumberTest测试运行我的测试

cucumberTest {
    useJUnitPlatform()
}

After migrating to cucumber-junit-platform-engine @CucumberOptions are no longer supported.迁移到cucumber-junit-platform-engine @CucumberOptions ,不再支持@CucumberOptions

package com.mycompany.cucumber;
import io.cucumber.junit.platform.engine.Cucumber;
@Cucumber
public class CucumberRunner {
}

I can make it work with replacing plugin , tags , glue options with properties cucumber.filter.tags , cucumber.glue , cucumber.plugin .我可以通过替换plugintagsglue选项和属性来实现它: cucumber.filter.tagscucumber.gluecucumber.plugin

What about features property? features属性呢? It works fine if I change feature files location to match package name ie resources/com/mycompany/cucumber/is_it_friday_yet.feature .如果我更改功能文件位置以匹配包名称,即resources/com/mycompany/cucumber/is_it_friday_yet.feature它工作正常。 Still this is a simple case and I have many more test packages which are not placed in the same locations as source code and I cannot move them.这仍然是一个简单的案例,我有更多的测试包,它们没有与源代码放在相同的位置,我无法移动它们。

Gradle doesn't support non-class based test engines . Gradle 不支持基于非类的测试引擎 However you can create a custom task that uses the JUnit Platform ConsoleLauncher .但是,您可以创建一个使用 JUnit 平台 ConsoleLauncher 的自定义任务 You can then use the Junit 5 selectors that are supported by Cucumber to select your features.然后,您可以使用Cucumber 支持Junit 5 选择器来选择您的功能。 For example the FileSelector with --select-file .例如带有--select-fileFileSelector

val consoleLauncherTest by tasks.creating(JavaExec::class) {
    dependsOn("testClasses")
    val reportsDir = file("$buildDir/test-results")
    outputs.dir(reportsDir)
    classpath(sourceSets["test"].runtimeClasspath)
    main = "org.junit.platform.console.ConsoleLauncher"
    args("--select-file", "path/to.feature")
    args("--details", "tree")
    args("--reports-dir", reportsDir)
}

In cucumber-jvm v7 the @Cucumber annotation is deprecated and you're encouraged to use the regular @Suite annotation.@Cucumber -jvm v7 中, @Cucumber注释已被弃用,我们鼓励您使用常规的@Suite注释。 This means you can also use annotations like @SelectClasspathResource to change the location of your feature files.这意味着您还可以使用@SelectClasspathResource类的@SelectClasspathResource来更改功能文件的位置。 This works for me:这对我有用:

@Suite
@IncludeEngines("cucumber")
@SelectClasspathResource("features")
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "com.mycompany.cucumber")
public class CucumberIT {
}

It picks up all my .feature files under the features/ dir in my resources folder (classpath)它在我的资源文件夹(类路径)中的features/目录下获取我所有的 .feature 文件

Docs: https://github.com/cucumber/cucumber-jvm/tree/main/junit-platform-engine#suites-with-different-configurations文档: https : //github.com/cucumber/cucumber-jvm/tree/main/junit-platform-engine#suites-with-different-configurations

There are various other @Select* annotations supported by junit-platform, I assume those work as well (though they're marked as experimental so subject to change): https://junit.org/junit5/docs/current/user-guide/#api-evolution-experimental-apis junit-platform 支持其他各种@Select*注释,我假设这些注释也能正常工作(尽管它们被标记为实验性的,因此可能会发生变化): https : //junit.org/junit5/docs/current/user-指南/#api-evolution-experimental-apis

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM