本文介绍了如何在gradle测试中禁用断言的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我使用了带disableassertions的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'//用于编译groovy 编译org.springframework:spring-core:3.0.5.RELEASE编译org.springframework:spring-aop:3.0.5.RELEASE compileorg.springframework:spring-asm:3.0.5.RELEASE compileorg.springframework:spring-beans:3.0 .RELEASE compileorg.springframework:spring-context:3.0.5.RELEASE compileorg.springframework:spring-expression:3.0.5.RELEASE compile org.springframework:spring-jdbc:3.0.5.RELEASE compileorg.springframework:spring-orm:3.0.5.RELEASE compileorg.springframework:spring-test:3.0 .5.RELEASE compilejunit:junit:4. + gradle test 输出 :booking:processResources UP-TO-DATE $ b $:预订:课程 : booking:jar :compileJava :compileGroovy :processResources UP-TO-DATE :classes :compileTestJava UP-TO-DATE $ b $:compileTestGroovy :processTestResources UP-TO-DATE :testClasses :test ScriptTester> testHandle FAILED ScriptTester.groovy上的java.lang.AssertionError:127 解决方案 .withType(Test){ jvmArgs...,...} 有一个启用或禁用断言的捷径: tasks.withType(Test){ enableAssertions = false } 有关更多API详细信息,请参阅手动构建语言参考。 I use JAVA_OPTS with disableassertions, but when gradle test is run, there are still outputs with java.lang.AssertionError. Why ?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 output :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:testScriptTester > testHandle FAILED java.lang.AssertionError at ScriptTester.groovy:127 解决方案 Gradle runs tests in separate JVM(s).To set arguments for these JVMs, use:tasks.withType(Test) { jvmArgs "...", "..."}There is a shortcut to enable or disable assertions:tasks.withType(Test) { enableAssertions = false}For further API details, see the Gradle Build Language Reference. 这篇关于如何在gradle测试中禁用断言的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-20 12:11
查看更多