Answer the question
In order to leave comments, you need to log in
Why shadowOf(activity).getOptionsMenu(); returns null?
Hello.
There is no experience with tests (somehow not everyone is ready to pay, and those who are ready do not have the tasks that require testing)
A simple example with robolectric
@RunWith(RobolectricGradleTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 21)
public class MainActivityTest {
@Test
public void onCreateShouldInflateTheMenu() {
Activity activity = Robolectric.setupActivity(MainActivity.class);
final Menu menu = shadowOf(activity).getOptionsMenu();
assertThat(menu.findItem(R.id.action_settings).getTitle()).isEqualTo("Settings");
}
}
@RunWith(RobolectricGradleTestRunner.class)
@Config(constants = BuildConfig.class, sdk = 21)
public class MainActivityTest {
@Test
public void onCreateShouldInflateTheMenu() {
Activity activity = Robolectric.setupActivity(MainActivity.class);
final Menu menu = shadowOf(activity).getOptionsMenu();
assertThat(menu).isEqualTo(null);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question