【问题标题】:JUnit 5 Gradle: Do test classes really have to be suffixed with "Test(s)"?JUnit 5 Gradle:测试类真的必须以“Test(s)”为后缀吗?
【发布时间】:2017-12-04 14:39:31
【问题描述】:

使用 Gradle 时,如果文件名和类名不以“Test”或“Tests”结尾,则似乎找不到 JUnit 5 测试。是否可以将 Gradle 配置为将 test 目录中的所有内容都视为测试类?

【问题讨论】:

    标签: gradle junit junit5 junit-jupiter


    【解决方案1】:

    来自this doc,请注意有一个名为“junit-platform-gradle-plugin”的插件。重点如下:

    junitPlatform {
        filters {
            includeClassNamePattern '.*'
        }
    }
    

    (相对于'.*TestCase')

    这是完整的build.gradle 文件(以及运行名为ExampleTestCase 和Example2 的测试的an example):

    apply plugin: 'java'
    
    buildscript {
        repositories {
            mavenCentral()
        }
        dependencies {
            classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.2'
        }
    }
    
    apply plugin: 'org.junit.platform.gradle.plugin'
    
    repositories {
        jcenter()
    }
    
    ext.junitJupiterVersion  = '5.0.2'
    
    dependencies {
        testCompile("org.junit.jupiter:junit-jupiter-api:${junitJupiterVersion}")
        testRuntime("org.junit.jupiter:junit-jupiter-engine:${junitJupiterVersion}")
    }
    
    junitPlatform {
        filters {
            includeClassNamePattern '.*'
        }
    }
    

    【讨论】:

    • 在我将正则表达式模式更新为 ^.* 之前,它无法在我的机器上运行,同时它也适用于我的同事。 ^.* 适合所有人
    猜你喜欢
    • 1970-01-01
    • 2017-12-23
    • 1970-01-01
    • 1970-01-01
    • 2021-01-06
    • 1970-01-01
    • 2018-09-30
    • 2019-05-30
    相关资源
    最近更新 更多