当前位置: 首页 > 知识库问答 >
问题:

Gradle 6.0.1不要运行我的Junit类。即使在我进入windows 10的gradle测试后构建成功

柴彬
2023-03-14

这是我的身材。格雷德尔锉刀

//应用java library插件以添加对java library应用插件的支持:“java library”

// In this section you declare where to find the dependencies of your project
repositories {
    jcenter()
}
//Gradle wrapper 
wrapper {
    gradleVersion = '6.0.1'
    distributionUrl = distributionUrl.replace("bin", "all")
}
sourceSets.main.java.srcDirs = ['src']
sourceSets.test.java.srcDirs = ['tst']

dependencies {
// Use JUnit test framework
testCompile 'junit:junit:4.12'
compile 'junit:junit:4.12'
runtime 'junit:junit:4.12'
// https://mvnrepository.com/artifact/junit/junit
testCompile group: 'junit', name: 'junit', version: '4.12'

}
test {

//How to run Gradle test when all tests are UP-TO-DATE?   add below line
      dependsOn 'cleanTest'
    //To enable this fail fast behavior so even a one unit test fail it keeps running 
        failFast = true

    useJUnitPlatform()
      // Give a different location to the gradle html reports in a folder called gradlehtmlReports
    reports.html.enabled = true
    reports.html.setDestination(file("$projectDir/gradlehtmlReports"))
}

我在src/test和src/main文件夹中都有类文件,但都没有被选中。当我输入gradle test时

package com.sam.home;
import static org.junit.Assert.assertEquals;

import org.junit.Test;

public class MyClassTest {
     @Test
        void testGet() {
            assertEquals("HelloJUnit 5", "Hello JUnit 5","Text mismatches");
        }




}

共有1个答案

百里意智
2023-03-14

您需要决定是使用JUnit 4还是5。现在您正在使用来自4的依赖关系,但声明您想要使用JUnit平台,这是一个仅来自版本5的概念。

如果要使用JUnit 4,请删除useJUnitPlatform()

如果你想使用JUnit 5,升级你的依赖项。

此外,不要对包装器使用distributionUrl hack,只需使用distributionType=wrapper即可。分布类型。全部。既然你在Gradle 6上,你应该修复你不推荐的配置(例如将编译更改为实现)。我还建议不要使用非标准的源目录,除非你有很好的理由不这样做——而且个人偏好不会超过长期以来的惯例:——

最后(抱歉,我有时会有些激动),如果你想一直执行单元测试,即使它们都是成功的和最新的,你可以通过不依赖于清理你的项目来加快构建速度,因为这意味着你必须重新编译你的类,即使它们没有改变。因此,不要使用dependsOn'cleanTest',而是使用输出。UpdateWhen{false}

 类似资料: