gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 03:56:11 24 4
gpt4 key购买 nike

这是我的build.gradle文件

//应用java-library插件添加对Java库的支持
Apply插件:“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");
}




}

最佳答案

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

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

如果要使用JUnit 5,请升级依赖项。

另外,不要使用分配器的distributionUrl hack,而只需使用distributionType = Wrapper.DistributionType.ALL即可。由于您在Gradle 6上,因此您应该修复deprecated configurations(例如,将compile更改为implementation)。我也建议不要使用非标准的源目录,除非您有很好的理由不这样做-并且个人喜好不胜过长期建立的约定:-)

最后(抱歉,有时我会感到迷惑),如果您想始终执行单元测试,即使它们都已经成功并且是最新的,则可以通过不依赖清理项目来加快构建速度,因为这样做会意味着即使您的类没有更改,也必须重新编译它们。因此,请使用dependsOn 'cleanTest'代替outputs.upToDateWhen { false }

关于gradle - Gradle 6.0.1不要运行我的Junit类。即使在Windows 10中进入gradle测试后构建成功,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59195816/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com