Why does the first test pass with Robolectric for so long?

I am testing my Android application using Robolectric, but it seemed strange to me. What happens is that when I run some test suite, the first test done with Robolectric takes much longer than any other test. This is not specific to the test itself, since I tried different configurations in order of tests, and the result is that the first test is always the slowest.

Is this some Robolectric installation time or something? Any information provided is helpful.

For example: Example of a slow first test

+7
android testing robolectric
source share
1 answer

Yes, this is the setup time. Unfortunately, there is no central place where you can collect all the information about Robolectric .

Watch this presentation and you will find more explanations on pages 28, 29, 30, 35.

If you're interested, Robolectric changed some approaches in version 2.0. Significant changes:

  • Javaassist use replaced by ASM use - to speed up startup time
  • They are trying to reduce the number of shadow classes and use the ASOP Android code instead - for better reliability of the test

If you are using gradle , also look at the robolectric gradle plugin . Added current tests are parallel and other settings. Passing tests in parallel, apparently, are useful only with a large number of tests (hundreds +)

+6
source share

All Articles