我有一个项目使用 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模板网!
更新到 Android Build Tools 25.1.6 GCM/FCM 后出现 IncompIncompatibleClassChangeError after updating to Android Build Tools 25.1.6 GCM / FCM(更新到 Android Build Tools 25.1.6 GCM/FCM 后出现 Incompatible
如何在 gradle 中获取当前风味How to get current flavor in gradle(如何在 gradle 中获取当前风味)
如何修复“意外元素<查询>在“清单How to fix quot;unexpected element lt;queriesgt; found in lt;manifestgt;quot; error?(如何修复“意外元素lt;查询gt;在“清单中找到错误
基于 Android Gradle 中多风味库的多风味应用Multi flavor app based on multi flavor library in Android Gradle(基于 Android Gradle 中多风味库的多风味应用)
Android 依赖在编译和运行时有不同的版本Android dependency has different version for the compile and runtime(Android 依赖在编译和运行时有不同的版本)
本地 aar 库的传递依赖Transitive dependencies for local aar library(本地 aar 库的传递依赖)