运行 gradlew 测试时 android 中的 Jvm 选项

Jvm options in android when run gradlew test(运行 gradlew 测试时 android 中的 Jvm 选项)
本文介绍了运行 gradlew 测试时 android 中的 Jvm 选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有一个项目使用 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 选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How can I use CClistview in COCOS2d Android?(如何在 COCOS2d Android 中使用 CClistview?)
cocos2d-android: how to display score(cocos2d-android:如何显示分数)
Sqlite database not copied from asset folder Android(Sqlite 数据库未从资产文件夹 Android 复制)
SQLite Database Copy Appears Corrupted When Generated by Device and not Emulator(SQLite 数据库副本在由设备而不是模拟器生成时出现损坏)
Android file copy(安卓文件拷贝)
Android how to detect Copy event of Edittext in android(Android如何在android中检测Edittext的Copy事件)