问题描述
我有一个项目使用 Robolectric 进行单元测试.本项目使用Robolectric 3.0,需要在虚拟机选项中添加-ea和-noverify选项.
I have a project that using Robolectric for unit test purpose. This project uses Robolectric 3.0 and need to add -ea and -noverify options in Virtual Machine options.
在 Android Studio 中,我在 Run > 中创建了新的 JUnit 配置.编辑配置...,然后将 VM Options 设置为 -ea -noverify.通过这种方式,我成功地运行了我的单元测试.这是关于我的配置的图片,请查看此处
In Android Studio, I created new JUnit configuration in Run > Edit Configurations... and then set VM Options to -ea -noverify. With this way I success to run my unit test. This is image about my configure, view Here
但是,对于持续部署,我需要使用命令行运行单元测试.所以我使用 ./gradlew test 来运行单元测试.我还将 org.gradle.jvmargs=-ea -noverify 添加到 gradle.properties 文件中.不幸的是,它不起作用.我可以运行单元测试,但我得到了 java.lang.VerifyError 并且我认为 gradle.properties 没有加载.
However, for continuous deployment, I need run unit test with command line. So I use ./gradlew test to run unit test. I also add org.gradle.jvmargs=-ea -noverify to gradle.properties file. Unfortunately, it doesn't work. I can run unit test but I got java.lang.VerifyError and I think that gradle.properties was not load.
所以,我的问题是,如何让 gradle.properties 加载,或者你知道有什么方法可以解决我的 vm 选项问题吗?
So, my question is, how to make gradle.properties load or do you know any way to fix my vm options problem?
推荐答案
发现我们可以在app的build.gradle中加入这个block来解决这个问题
I found that we can add this block to app's build.gradle to solve this problem
tasks.whenTaskAdded { theTask -> def taskName = theTask.name.toString() if ("testDevDebug".toString().equals(taskName)) { theTask.jvmArgs('-ea', '-noverify') } }
DevDebug 是我的构建变体.