Ste*_*dli 3 java junit gradle build.gradle junit5
我的项目使用gradle和JUnit 5.01。JUnit断言工作正常。但是,我在测试代码中的常规Java断言没有触发。我希望失败的断言会引发一个AssertionError,它将被JUnit捕获并报告。
我发现了这一点:如何在gradle test中禁用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'
}
}
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
深入研究gradle和大量的实验,使我发现替换
tasks.withType(Test) {
enableAssertions = true
}
Run Code Online (Sandbox Code Playgroud)
与
junitPlatformTest {
enableAssertions = true
}
Run Code Online (Sandbox Code Playgroud)
做到了。我不知道为什么
归档时间: |
|
查看次数: |
1509 次 |
最近记录: |