cucumber-junit-platform-engine 中的功能文件发现 [英] Feature files discovery in cucumber-junit-platform-engine

查看:31
本文介绍了cucumber-junit-platform-engine 中的功能文件发现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

cucumber-junit 库中,我使用 @CucumberOptions 来定义功能文件位置:

In cucumber-junit library I use @CucumberOptions to define feature files location:

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 {
}

我正在使用自定义 gradle 任务 cucumberTest

I'm running my tests with custom gradle task cucumberTest

cucumberTest {
    useJUnitPlatform()
}

迁移到 cucumber-junit-platform-engine 后,不再支持 @CucumberOptions.

After migrating to cucumber-junit-platform-engine @CucumberOptions are no longer supported.

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

我可以通过将 plugintagsglue 选项替换为属性 cucumber.filter.tags, cucumber.glue, cucumber.plugin.

I can make it work with replacing plugin, tags, glue options with properties cucumber.filter.tags, cucumber.glue, cucumber.plugin.

features 属性呢?如果我更改功能文件位置以匹配包名称,即 resources/com/mycompany/cucumber/is_it_friday_yet.feature,它工作正常.这仍然是一个简单的案例,我还有更多的测试包没有放在与源代码相同的位置,我无法移动它们.

What about features property? It works fine if I change feature files location to match package name i.e. 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不支持基于非类的测试引擎.但是,您可以创建 自定义任务使用 JUnit Platform ConsoleLauncher.然后,您可以使用 Junit 5 选择器支持 Cucumber 选择您的功能.例如 FileSelector--select-file.

Gradle doesn't support non-class based test engines. However you can create a custom task that uses the JUnit Platform ConsoleLauncher. You can then use the Junit 5 selectors that are supported by Cucumber to select your features. For example the FileSelector with --select-file.

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)
}

这篇关于cucumber-junit-platform-engine 中的功能文件发现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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