Configuration

suggest change

Add Robolectric's @Config annotation to a test class or method.

Run with custom Application class

@RunWith(RobolectricTestRunner.class)
@Config(application = MyApplication.class)
public final class MyTest {
}

Set target SDK

@RunWith(RobolectricTestRunner.class)
@Config(sdk = Build.VERSION_CODES.LOLLIPOP)
public final class MyTest {
}

Run with custom manifest

When manifest is set, Robolectric resolves that path from the current directory. The default value is AndroidManifest.xml.

Resources and assets will be loaded relative to the manifest.

@RunWith(RobolectricTestRunner.class)
@Config(manifest = "path/AndroidManifest.xml")
public final class MyTest {
}

Use qualifiers

Qualifier names are listed in the Android resource docs.

@RunWith(RobolectricTestRunner.class)
public final class MyTest {

    @Config(qualifiers = "sw600dp")
    public void testForTablet() {
    }
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents