Java GC是否通过将弱引用放在分配给该引用的ReferenceQueue上来自动清除弱引用?换句话说,如果对WeakReference.get()的调用返回null,则WeakReference是否在队列中?
我的项目使用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 '.*' …Run Code Online (Sandbox Code Playgroud)