android-studio-unit-test-plugin
android-studio-unit-test-plugin copied to clipboard
Add default VM options to test runs
I have a project set up with android-unit-test and android-studio-unit-test-plugin. When I right-click on a Robolectric test class and run it as a JUnit test, the test fails with a VerifyError. See https://github.com/robolectric/robolectric/issues/1186.
The current workaround is to add -noverify as a VM argument. I've been able to do this with the following block in my build.gradle file. When I run tests on the command line (./gradlew test), the tests work properly.
androidUnitTest {
testTasks {
all {
jvmArgs '-noverify'
}
}
}
This configuration doesn't translate to the automatically generated run configurations in Android Studio when I run a single test class. I also haven't had any luck modifying the default JUnit configuration in the Edit Configurations dialog. Instead, my workaround is to try to run a test, modify the automatically generated run configuration to add -noverify to the VM options, then run the test again.
As a feature request, I'd like a way to set default VM options to be added to every test run.
I seem to be able to set the VM options in the Run/Debug Configurations dialog fine but they reset whenever the project syncs / reloads.
Yep, that's an issue. Maybe a quick way to solve this would be to detect and change only the generated java options instead of blowing them away. Even better would be to read the gradle config, but I'm not sure that's possible since as far as I know, there is no way to pass it to the IDE using the standard android model.
Can you just add -noverify option by default to work around the Java 1.7 + robolectric issues? On Jan 15, 2015 7:21 PM, "Evan Tatarka" [email protected] wrote:
Yep, that's an issue. Maybe a quick way to solve this would be to detect and change only the generated java options instead of blowing them away. Even better would be to read the gradle config, but I'm not sure that's possible since as far as I know, there is no way to pass it to the IDE using the standard android model.
— Reply to this email directly or view it on GitHub https://github.com/evant/android-studio-unit-test-plugin/issues/35#issuecomment-70134206 .
I don't feel comfortable hard-coding that option since it really shouldn't be something you should be passing all the time. I think making it possible to specify it yourself should be good enough and more flexible.
+1 to not blowing away custom VM options. We run into OutOfMemory issues with our tests so need to tweak -Xms, -Xmx, -XX:MaxPermSize, etc. I also want to check the run configuration into source control for all our devs.
Is there any way to programmatically check, if -noverify is set on the VM?
I thought it would be useful for other as well, so I asked the question on StackOverflow