Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is does the first test run with Robolectric taking so long?

I'm testing my Android app with Robolectric but I faced a weird situation. What happens is that when I run some set of tests, the first test ran with Robolectric takes much more time than any other test. It is not specific from the test itself, since I tried different configurations on the order of the tests and the result is that the first test is always the slowest.

Is it any Robolectric setup time or something like that? Any information provided is useful.

For example: Example of slow first test

like image 886
Fábio Carballo Avatar asked Jan 07 '15 11:01

Fábio Carballo


Video Answer


1 Answers

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

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

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

  1. Javaassist usage replaced with ASM usage - for speedup start time
  2. They try to reduce number of shadow classes and use ASOP Android code instead - for better test reliability

If you use gradle then take a look also on robolectric gradle plugin. The added running tests in parallel and other tuning options. The running tests in parallel apparently useful only with big amount of tests (hundreds+)

like image 135
Eugen Martynov Avatar answered Oct 06 '22 12:10

Eugen Martynov