1

I'm working on Android code that includes a differentiation between two Android versions.

I wrote tests to run the code. I'm using Robolectric.

I found a SO answer that says how to configure the version that Robolectric uses for running the test:
Does Robolectric support API level?
But that way I'd have to copy the test and use different annotations (or rather have the test code in a private method and create two new public test methods that call the private method - but I've already got hundreds of tests, so this would be lots of work).

Is there any way to tell Robolectric to run a test twice, with different Android versions for each run?

Community
  • 1
  • 1
backendev
  • 267
  • 6
  • 15

1 Answers1

3

I know your answer has been posted a year ago but I had the same problem and I found no answer on the web.

I found a solution with Robolectric 3.0 : you can use the class MultiApiRobolectricTestRunner. For example :

@RunWith(MultiApiRobolectricTestRunner.class)
@Config(constants = BuildConfig.class, manifest=Config.NONE, sdk = {16, 19, 21})
public class MyTestCase extends TestCase {

    @Test
    public void test1ToRunOnMultipleApis(){
        // My test
    }
}

The method test1ToRunOnMultipleApis will be tested 3 times : with API 16, 19 and 21.

Hope this can help ;)

Regis
  • 73
  • 8