首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法在子粒上运行黄瓜JUnit测试

无法在子粒上运行黄瓜JUnit测试
EN

Stack Overflow用户
提问于 2019-12-23 13:23:41
回答 2查看 1.8K关注 0票数 1

我正在尝试使用IntelliJ Community和Gradle 5.5.1运行一个黄瓜/ Selenium项目。

我的文件夹结构如下:

代码语言:javascript
复制
ProjectRoot
|
src---main---java
|
src---test---java---packagename---stepdefinitions---Steps.java
        |
        -----resources---feature---application.feature

我的TestRunner类如下:

代码语言:javascript
复制
@RunWith(Cucumber.class)
@CucumberOptions(
        plugin = {"pretty", "json:cucumber-report.json"},
        features = {"src/test/resources/feature"})
public class TestRunner {
}

当我尝试运行TestRunner时,我得到的结果如下:

代码语言:javascript
复制
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

代码语言:javascript
复制
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任务时,我得到

代码语言:javascript
复制
BUILD SUCCESSFUL in 0s
4 actionable tasks: 1 executed, 3 up-to-date
18:52:41: Task execution finished 'test'.

不运行Cucumber方案。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-12-23 13:43:58

JUnit运行ˋ是一种ˋ4机制。为了使用JUnit 5平台机制,您必须包括对junit-vintage引擎的依赖,该引擎允许在JUnit 5上运行JUnit 4测试。

或者,您可以更改为JUnit 5的黄瓜引擎。我不确定它是否已经发布。

票数 2
EN

Stack Overflow用户

发布于 2021-07-18 11:47:23

从医生那里,

黄瓜是基于JUnit 4的,如果您使用的是JUnit 5,请记住还包括junit-vintage引擎依赖项。有关更多信息,请参阅JUnit 5文档。

添加以下依赖项使其在IntelliJ上工作:

代码语言:javascript
复制
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")

查看这里以获得更多详细信息

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59456120

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档