[英]Enabling assertions in Gradle/JUnit
我的项目使用gradle和JUnit 5.01。 JUnit断言工作正常。 但是,我在测试代码中的常规Java断言并未触发。 我希望失败的断言能够抛出一个将被JUnit捕获并报告的AssertionError。
我发现了这个: 如何在gradle测试中禁用assert ,因此创建了这个build.gradle:
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.2'
}
}
apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'maven'
apply plugin: 'org.junit.platform.gradle.plugin'
compileJava {
options.compilerArgs += "-Xlint:unchecked"
}
tasks.withType(Test) {
enableAssertions = true
}
repositories {
mavenCentral()
}
dependencies {
testCompile('org.junit.jupiter:junit-jupiter-api:5.0.1')
testCompile('org.apiguardian:apiguardian-api:1.0.0')
testRuntime('org.junit.jupiter:junit-jupiter-engine:5.0.1')
}
// Define the main class for the application
mainClassName = 'CMS'
jar {
manifest {
attributes 'Implementation-Title': 'CMS',
'Main-Class': 'com.brandli.cms.CMS'
}
}
junitPlatform {
filters {
includeClassNamePattern '.*'
}
}
test {
testLogging {
exceptionFormat = 'full'
}
}
我究竟做错了什么?
挖到gradle,并进行了大量的实验,让我找到了替换
tasks.withType(Test) {
enableAssertions = true
}
同
junitPlatformTest {
enableAssertions = true
}
做了伎俩。 我不知道为什么。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.