Sometimes tests take a very long time to run in Android Studio. 2+ minutes, and other times only ~7 seconds.
I've recently added Robolectric to my teams pure Kotlin application. We have a handful of Android JUnit tests as well, but needed something more powerful. In using the current Android Studio version (2.3.3) In adding my first test I noticed that while running the tests in Android Studio (I haven't reproduced this while running with ./gradlew test), about 25% of the time, the tests will hang and take an extraordinarily long time to run. A test that would normally run in 7 seconds, can sometimes take 2+ minutes for no clear reason.
I can tell Android studio to run a single class of tests, with a single test that takes 1-2 minutes:
@Test fun exampleTest() {
println("Test is now running")
}
Robolectric.buildActivity(MainActivity::class.java)
.create()
.start()
.resume()
.visible()
.get()
Android Plugin 2.3.3
Robolectric 3.3.2
Compile SDK 25
I believe this issue is related to using Robolectric with PowerMock at the same time. When I removed powermock, my tests are consistently fast.
EDIT: It runs fast until I start using the ActivityLifecycle.
I can confirm this issue. Using Android Studio 3.0, i have a very very simple test that starts a fragment and verifies some textfields on it. In Android Studio, it takes like 4 Minutes (!!!!!!!) to execute, in the console it runs in under 5 seconds.
Using Robolectric 3.5.1
I also noticed that using the incubating mock-maker-inline feature from Mockito slows down my tests by about 30%.
Most helpful comment
I believe this issue is related to using Robolectric with PowerMock at the same time. When I removed powermock, my tests are consistently fast.
EDIT: It runs fast until I start using the ActivityLifecycle.