How do I use robolectric in Android Studio

0

Hello, I'd like to know how I use robolectric in my projects in Android Studio. I've tried a lot of tutorials, but none was a big help and the documentation is not very clear.

    
asked by anonymous 15.01.2015 / 22:54

1 answer

1

First, include the jar in the dependencies of your project.

Next, 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"));
    }
}

It is recommended to use Maven with the plugin .

More uses see here .

    
19.01.2015 / 14:13