使用gradle测试执行Junit5 ExtendedCucumber测试

时间:2017-12-05 18:15:14

标签: gradle cucumber-java junit5

我希望能够使用gradle test执行ExtendedCucumber类,而不是定义一个调用cucumber.api.cli.Main类的单独黄瓜任务。

我有以下ExtendedCucumber测试运行器:

import com.github.mkolisnyk.cucumber.runner.ExtendedCucumber 
import com.github.mkolisnyk.cucumber.runner.ExtendedCucumberOptions
import cucumber.api.CucumberOptions
import org.junit.runner.RunWith

@RunWith(ExtendedCucumber::class)
@ExtendedCucumberOptions(jsonReport = "build/test-results/cucumber/cucumber-
report.json",
    retryCount = 3,
    detailedReport = true,
    detailedAggregatedReport = true,
    overviewReport = true,
    //coverageReport = true,
    jsonUsageReport = "build/test-results/cucumber/cucumber-report.json",
    usageReport = false,
    toPDF = true,
    excludeCoverageTags = ["@flaky"],
    includeCoverageTags = ["@passed"],
    outputFolder = "build/test-results/cucumber")
@CucumberOptions(
    plugin = ["pretty:build/test-results/cucumber/cucumber-pretty.txt", "html:build/test-results/cucumber/cucumber-html-report",
        "json:build/test-results/cucumber/cucumber-report.json", "usage:build/test-results/cucumber/cucumber-usage.json",
        "junit:build/test-results/cucumber/cucumber-results.xml"],
    glue = ["io.biomex.spog.steps"],
    features = ["classpath:features"])
class RunCukesJunitTest

从我的IDE按预期执行,创建扩展报告。并且gradle中的以下Junit5配置:

junitPlatform {
    platformVersion '1.0.2'
    reportsDir file('build/test-results/junit-platform') // this is the default
    filters {
        engines {
            include 'junit-jupiter'
            // exclude 'custom-engine'
        }
        tags {
            // include 'fast'
            //exclude 'slow'
        }
        selectors {
            file 'RunCukesJunitTest'
        }
        //includeClassNamePattern '^.*Test?'
        //excludeClassNamePattern '^.*Jpa?'
    }
    // enableStandardTestTask true
    // reportsDir file('build/test-results/junit-platform') // this is the default
    //logManager 'org.apache.logging.log4j.jul.LogManager'
}

可以很好地查找和执行普通的Junit测试。如您所见,我已将Junit5配置为仅执行RunCukesJunitTest。构建正常运行,检测测试,但不会对以下输出运行任何测试:

Test run finished after 47 ms
[         1 containers found      ]
[         0 containers skipped    ]
[         1 containers started    ]
[         0 containers aborted    ]
[         1 containers successful ]
[         0 containers failed     ]
[         0 tests found           ]
[         0 tests skipped         ]
[         0 tests started         ]
[         0 tests aborted         ]
[         0 tests successful      ]
[         0 tests failed          ]



BUILD SUCCESSFUL in 13s
6 actionable tasks: 6 executed

我可以使用自定义gradle任务运行普通的Cucumber测试:

task cucumber() {
    dependsOn assemble, compileTestJava
    doLast {
        javaexec {
            main = "cucumber.api.cli.Main"
            classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
            args = ['--plugin', 'html:build/test-results/cucumber/cucumber-html-report',
                '--plugin', 'json:build/test-results/cucumber/cucumber-report.json',
                '--plugin', 'pretty:build/test-results/cucumber/cucumber-pretty.txt', '--glue', 'io.biomex.spog.steps', 'src/test/resources/features/api']
        }
    }
}

我认为我可以改变上述任务来执行ExtendedCucumber任务。但是,理想情况下,我希望所有Junit测试,包括在运行命令gradle testgradle junitPlatformTest时执行黄瓜测试。

0 个答案:

没有答案