Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jvm options in android when run gradlew test

Tags:

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?

like image 421
Pi Vinci Avatar asked Aug 31 '15 16:08

Pi Vinci


People also ask

How do I run a Gradlew test?

In your Gradle project, in the editor, create or select a test to run. From the context menu, select Run <test name>. icon in the left gutter. If you selected the Choose per test option, IntelliJ IDEA displays both Gradle and JUnit test runners for each test in the editor.

Which Java framework is used to write unit tests in android?

JUnit is a “Unit Testing” framework for Java Applications which is already included by default in android studio. It is an automation framework for Unit as well as UI Testing. It contains annotations such as @Test, @Before, @After, etc.

How run all test cases in Android?

Run all tests in a single classRight click on a test class name in the editor (or a filename in the project explorer) to run all tests in a single class. The default keyboard shortcut for this is Ctrl+Shift+F10 on Linux. I suggest you map it to something easier to remember like Ctrl+Alt+R.


2 Answers

It is already answered but this may be an easier solution:

In your application modules' build.gradle file in android closure, add this.

android {   ....    testOptions {     unitTests.all {       jvmArgs '-noverify'     }   } } 
like image 75
tasomaniac Avatar answered Sep 24 '22 13:09

tasomaniac


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.

like image 41
Pi Vinci Avatar answered Sep 25 '22 13:09

Pi Vinci