在运行gradlew测试时,android中的jvm选项 [英] Jvm options in android when run gradlew test

查看:527
本文介绍了在运行gradlew测试时,android中的jvm选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Robolectric进行单元测试的项目。该项目使用Robolectric 3.0,并且需要在虚拟机选项中添加 -ea -noverify 选项。

在Android Studio中,我在 Run>中创建了新的JUnit配置。编辑配置... ,然后将 VM选项设置为 -ea -noverify 。通过这种方式,我成功地运行了我的单元测试。这是关于我的配置的图像,查看这里

但是,对于持续部署,我需要使用命令行运行单元测试。所以我使用 ./ gradlew test 来运行单元测试。我还将 org.gradle.jvmargs = -ea -noverify 添加到 gradle.properties 文件中。不幸的是,它不起作用。我可以运行单元测试,但得到了 java.lang.VerifyError ,我认为 gradle.properties 没有加载。

所以,我的问题是,如何让 gradle.properties 加载,或者您是否知道解决我的问题的方法vm options problem?

解决方案

我发现我们可以将此块添加到应用程序的build.gradle中来解决此问题。

  tasks.whenTaskAdded {th​​eTask  - > 
def taskName = theTask.name.toString()
if(testDevDebug.toString()。equals(taskName)){
theTask.jvmArgs(' - ea','-noverify ')
}
}

DevDebug code>是我的构建变体。


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.

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

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.

So, my question is, how to make gradle.properties load or do you know any way to fix my vm options problem?

解决方案

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 is my build variant.

这篇关于在运行gradlew测试时,android中的jvm选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆