I've written up some instrumented tests, and the assertions are passing - however regardless of what configuration they are run in, the run never terminates/ends - I have to manually terminate the run - which is not optimal for a CI setup.
I have tried running the below code in the following run configurations:
Even if I take out my test code and put in incredibly simple tests (as I have done below) the code execution does not complete.
public class TestClass {
private MainActivity mainActivity;
private MyScreen myScreenInstance;
@Rule
public ActivityTestRule mActivityRule = new ActivityTestRule<>(MainActivity.class);
@Before
public void setUp() throws FileNotFoundException {
mainActivity = (MainActivity) mActivityRule.getActivity();
}
@Test
public void test_1() throws FileNotFoundException {
assertEquals(1,2);
}
@Test
public void test_2() throws FileNotFoundException {
assertEquals(2,2);
}
}
For context I'm trying to test that a touch behaviour in a class I have written on top of a simple game engine written by a lecturer, the test code and assertions I have written all work - but the problem is that the run does not complete.
Do I have to have some sort of 'teardown' method to destroy the ActivityTestRule
? What can I do to ensure this run completes correctly?
Interestingly these very simple assertions successfully run on API 25 on a Nexus 7 emulator, however when run in a Nexus 5 emulator running API 23 the tests do not complete as described above.
Further information:
Below is a picture of a run I started, and then 5 minutes later it's hung. It should have completed 2 tests in < 2 seconds.
I have now resolved this issue, ordinarily a developer would be adding a onView
call, however due to the nature of the framework i am working in I was not doing so. I have added
onView(withId(R.id.activity_fragment_id)).perform(click());
to the setup, to just click the main area that the game runs within and now tests pass.