I upgraded to Android Studio 2.0 from 1.5 yesterday on Ubuntu. When I unit-test in Android Studio 2.0, it shows Terminated test status even though all tests are passed. Sometimes it shows only some of the tests passed. I'm pretty sure my code is working and tests are correct, because I had same setup on Android Studio 1.5.
For example I have 22 tests. Sometimes it shows all 22 tests passed, on the next run it shows 21 of 22 tests passed, sometimes Stopped. 20 of 22 tests passed, other times it shows all 20 tests passed even though I have 22 test. It all happens randomly. No failure message is shown.
I found an answer about Android studio on a similar IntelliJ issue that turning off Instant Run to Hot Swap resolves the issue. But that didn't solve the problem.
I tried running tests in Android Studio 1.5 but no problems.
Has anyone encountered any such issues in Android Studio 2.0, did you find any fix for this? Any help is much appreciated. Thanks!
When you use AndroidJUnitRunner to run your tests, you can access the context for the app under test by calling the static ApplicationProvider. getApplicationContext() method. If you've created a custom subclass of Application in your app, this method returns your custom subclass's context.
Robolectric is a framework that allows you to write unit tests and run them on a desktop JVM while still using Android API. Robolectric provides a JVM compliant version of the android. jar file.
To run all tests in a class or a specific method, open the test file in the Code Editor and do either of the following: Press the Run test icon in the gutter. Right-click on the test class or method and click Run . Select the test class or method and use shortcut Control+Shift+R .
This sounds like a known bug. The description on the bug report does not indicate some test not being run occasionally though.[1] I am running into similar issues but all the tests are run.
There seems to be a fix on the way probably in Android Studio 2.1.
[1] https://code.google.com/p/android/issues/detail?id=201968
I would like to confirm that Android Studio 2.1 has been released. I just updated to Android Studio 2.1 and Android Gradle plugin 2.1.0 and this issue has been fixed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With