我有一个项目使用 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
是我的构建变体.
这篇关于运行 gradlew 测试时 android 中的 Jvm 选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!