How to use robolectric in Android Studio

Asked

Viewed 150 times

0

Hello, I’d like to know how I use robolectric in my projects on Android Studio. I have tried several tutorials, but none was of great help and the documentation of it is not very clear.

1 answer

1

First, include the jar in your project dependencies.

Then use the annotation RunWith (Available in Junit4):

Example:

@RunWith(RobolectricTestRunner.class)
public class TesteRobolectric {
    @Test
    public void aplicacao() throws Exception {
        String appName = new RobolectricUso().getResources().getString(R.string.app_name);
        assertThat(appName, equalTo("RobolectricUso"));
    }
}

Recommended is to use Maven with plugin.

More uses see here.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.