I’m testing a destroy/restart sequence to make sure a counter retains its original value (before it was being incorrectly incremented on the restart). I put a fix in and it worked, when I test manually. But the unit test always passes, whether I include the fix or not. As you can see in the code below, I’m getting the counter value, then restarting, getting the counter value again and comparing them. What could be the problem?
public void testNumCorrectEqualAfterDestroy() {
mCorrect = (TextView) mActivity.findViewById(R.id.correct);
int before = Integer.parseInt(mCorrect.getText().toString());
mActivity.finish();
mActivity = this.getActivity();
mCorrect = (TextView) mActivity.findViewById(R.id.correct);
int after = Integer.parseInt(mCorrect.getText().toString());
Assert.assertEquals(before, after);
}
I think finish() will not cycle your activity through the “appropriate” states. The way I’ve tested this lifecycle case before is like so: