簡體   English   中英

在Gradle / JUnit中啟用斷言

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM