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.
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.
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 .