問題描述
我有一個項(xiàng)目使用 Robolectric 進(jìn)行單元測試.本項(xiàng)目使用Robolectric 3.0,需要在虛擬機(jī)選項(xiàng)中添加-ea
和-noverify
選項(xiàng).
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 > 中創(chuàng)建了新的 JUnit 配置.編輯配置...
,然后將 VM Options
設(shè)置為 -ea -noverify
.通過這種方式,我成功地運(yùn)行了我的單元測試.這是關(guān)于我的配置的圖片,請查看此處
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
但是,對于持續(xù)部署,我需要使用命令行運(yùn)行單元測試.所以我使用 ./gradlew test
來運(yùn)行單元測試.我還將 org.gradle.jvmargs=-ea -noverify
添加到 gradle.properties
文件中.不幸的是,它不起作用.我可以運(yùn)行單元測試,但我得到了 java.lang.VerifyError
并且我認(rèn)為 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 選項(xiàng)問題嗎?
So, my question is, how to make gradle.properties
load or do you know any way to fix my vm options problem?
推薦答案
發(fā)現(xiàn)我們可以在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
是我的構(gòu)建變體.
這篇關(guān)于運(yùn)行 gradlew 測試時 android 中的 Jvm 選項(xiàng)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!