无法 运行 在 Gradle 上进行黄瓜 JUnit 测试
Cannot run cucumber JUnit tests on Gradle
我正在尝试 运行 使用 IntelliJ 社区版和 Gradle 5.5.1 的 Cucumber/Selenium 项目。
我的文件夹结构如下:
ProjectRoot
|
src---main---java
|
src---test---java---packagename---stepdefinitions---Steps.java
|
-----resources---feature---application.feature
我的TestRunnerclass如下:
@RunWith(Cucumber.class)
@CucumberOptions(
plugin = {"pretty", "json:cucumber-report.json"},
features = {"src/test/resources/feature"})
public class TestRunner {
}
当我尝试 运行 TestRunner 时,我得到的是以下内容:
Testing started at 18:48 ...
> Task :cleanTest
> Task :compileJava UP-TO-DATE
> Task :processResources NO-SOURCE
> Task :classes UP-TO-DATE
> Task :compileTestJava
> Task :processTestResources UP-TO-DATE
> Task :testClasses
> Task :test FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':test'.
> No tests found for given includes: [org.fifthgen.scanmaltatesting.TestRunner](filter.includeTestsMatching)
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1s
5 actionable tasks: 3 executed, 2 up-to-date
这是我的 build.gradle
:
plugins {
id 'java'
}
group 'org.fifthgen'
version '1'
sourceCompatibility = 11
targetCompatibility = 11
repositories {
mavenCentral()
}
wrapper.gradleVersion = '5.5.1'
def cucumberVersion = '4.7.2'
def junitVersion = '5.5.2'
dependencies {
implementation 'org.seleniumhq.selenium:selenium-java:3.141.59'
testImplementation "io.cucumber:cucumber-java:${cucumberVersion}"
testImplementation "io.cucumber:cucumber-junit:${cucumberVersion}"
testImplementation "org.junit.jupiter:junit-jupiter-api:${junitVersion}"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junitVersion}"
}
test {
useJUnitPlatform()
scanForTestClasses = false
}
当我使用 Gradle 运行 test
任务时,我得到
BUILD SUCCESSFUL in 0s
4 actionable tasks: 1 executed, 3 up-to-date
18:52:41: Task execution finished 'test'.
没有 Cucumber 场景运行。
ˋRunWithˋ是一种JUnit 4 机制。为了将其与 JUnit 5 平台机制一起使用,您必须包括对 junit-vintage 引擎的依赖,它允许 运行 在 JUnit 5 上进行 JUnit 4 测试。
或者,您可以更改为 JUnit 5 的 Cucumber 引擎。我不确定它是否已经发布。
来自文档,
Cucumber is based on JUnit 4. If you’re using JUnit 5, remember to include junit-vintage-engine dependency, as well. For more information, please refer to JUnit 5 documentation.
添加以下依赖项使其在 IntelliJ 上运行:
testRuntimeOnly("org.junit.platform:junit-platform-launcher:1.7.2")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.7.2")
testRuntimeOnly("org.junit.vintage:junit-vintage-engine:5.7.2")
查看here了解更多详情
我正在尝试 运行 使用 IntelliJ 社区版和 Gradle 5.5.1 的 Cucumber/Selenium 项目。
我的文件夹结构如下:
ProjectRoot
|
src---main---java
|
src---test---java---packagename---stepdefinitions---Steps.java
|
-----resources---feature---application.feature
我的TestRunnerclass如下:
@RunWith(Cucumber.class)
@CucumberOptions(
plugin = {"pretty", "json:cucumber-report.json"},
features = {"src/test/resources/feature"})
public class TestRunner {
}
当我尝试 运行 TestRunner 时,我得到的是以下内容:
Testing started at 18:48 ...
> Task :cleanTest
> Task :compileJava UP-TO-DATE
> Task :processResources NO-SOURCE
> Task :classes UP-TO-DATE
> Task :compileTestJava
> Task :processTestResources UP-TO-DATE
> Task :testClasses
> Task :test FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':test'.
> No tests found for given includes: [org.fifthgen.scanmaltatesting.TestRunner](filter.includeTestsMatching)
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1s
5 actionable tasks: 3 executed, 2 up-to-date
这是我的 build.gradle
:
plugins {
id 'java'
}
group 'org.fifthgen'
version '1'
sourceCompatibility = 11
targetCompatibility = 11
repositories {
mavenCentral()
}
wrapper.gradleVersion = '5.5.1'
def cucumberVersion = '4.7.2'
def junitVersion = '5.5.2'
dependencies {
implementation 'org.seleniumhq.selenium:selenium-java:3.141.59'
testImplementation "io.cucumber:cucumber-java:${cucumberVersion}"
testImplementation "io.cucumber:cucumber-junit:${cucumberVersion}"
testImplementation "org.junit.jupiter:junit-jupiter-api:${junitVersion}"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:${junitVersion}"
}
test {
useJUnitPlatform()
scanForTestClasses = false
}
当我使用 Gradle 运行 test
任务时,我得到
BUILD SUCCESSFUL in 0s
4 actionable tasks: 1 executed, 3 up-to-date
18:52:41: Task execution finished 'test'.
没有 Cucumber 场景运行。
ˋRunWithˋ是一种JUnit 4 机制。为了将其与 JUnit 5 平台机制一起使用,您必须包括对 junit-vintage 引擎的依赖,它允许 运行 在 JUnit 5 上进行 JUnit 4 测试。
或者,您可以更改为 JUnit 5 的 Cucumber 引擎。我不确定它是否已经发布。
来自文档,
Cucumber is based on JUnit 4. If you’re using JUnit 5, remember to include junit-vintage-engine dependency, as well. For more information, please refer to JUnit 5 documentation.
添加以下依赖项使其在 IntelliJ 上运行:
testRuntimeOnly("org.junit.platform:junit-platform-launcher:1.7.2")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.7.2")
testRuntimeOnly("org.junit.vintage:junit-vintage-engine:5.7.2")
查看here了解更多详情