【问题标题】:How to disable assert in gradle test如何在 gradle 测试中禁用断言
【发布时间】:2014-10-16 08:17:10
【问题描述】:

我使用带有禁用断言的 JAVA_OPTS,但是当运行 gradle test 时,仍然有带有 java.lang.AssertionError 的输出。为什么?

build.gradle

apply plugin: 'java'

apply plugin: 'eclipse'

apply plugin: "groovy"

dependencies {

    compile 'org.codehaus.groovy:groovy-all:2.3.6'  // for compile groovy
    compile "org.springframework:spring-core:3.0.5.RELEASE"
    compile "org.springframework:spring-aop:3.0.5.RELEASE"
    compile "org.springframework:spring-asm:3.0.5.RELEASE"
    compile "org.springframework:spring-beans:3.0.5.RELEASE"
    compile "org.springframework:spring-context:3.0.5.RELEASE"
    compile "org.springframework:spring-expression:3.0.5.RELEASE"
    compile "org.springframework:spring-jdbc:3.0.5.RELEASE"
    compile "org.springframework:spring-orm:3.0.5.RELEASE"
    compile "org.springframework:spring-test:3.0.5.RELEASE"
    compile "junit:junit:4.+"
}

gradle test 输出

:booking:processResources UP-TO-DATE 

:booking:classes

:booking:jar

:compileJava

:compileGroovy

:processResources UP-TO-DATE

:classes

:compileTestJava UP-TO-DATE

:compileTestGroovy

:processTestResources UP-TO-DATE

:testClasses

:test

ScriptTester > testHandle FAILED
    java.lang.AssertionError at ScriptTester.groovy:127

【问题讨论】:

  • 发布你的 gradle 脚本。
  • BTY ,我在测试用例中使用 SpringJUnit4ClassRunner 。
  • 你在测试中有错误吗?
  • Groovy 断言与 Java 断言不同 - 您不能关闭 Groovy 断言。

标签: gradle assert


【解决方案1】:

Gradle 在单独的 JVM 中运行测试。要为这些 JVM 设置参数,请使用:

tasks.withType(Test) {
    jvmArgs "...", "..."
}

有一个启用或禁用断言的快捷方式:

tasks.withType(Test) {
    enableAssertions = false
}

有关更多 API 详细信息,请参阅Gradle Build Language Reference

【讨论】:

  • 谢谢,现在断言已禁用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-02-11
  • 1970-01-01
  • 2014-10-21
  • 1970-01-01
  • 2021-12-05
  • 2018-10-21
相关资源
最近更新 更多