问题描述
我有一个项目使用 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设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)