Issue
Can someone teach me how to test the sample code below?
How to I write espresso test for this? Since no view action is required?
public class SampleActivity extends AppCompatActivity {
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
Intent intent = new Intent(this, NextActivity.class);
startActivity(intent);
}
}
I would want to test whether the activity was actually started. Please help me. Thanks in advance.
Solution
This has been answered multiple times:
- From obtaining the activity at the time of test execution:
How can I check if the new activity was started
- To the usage of
espresso-intents
artifact (preferred option):
How to validate whether opened correct activity - Espresso
Keep in mind that the usage of IntentsTestRule
might be problematic here, it used to call Intents.init()
after your activity is launched, which will be too late as you will already be in the new activity. Not sure if this behavior is still in place, but you can work this around by calling init()
manually in @Before
method of your test class, don't forget to do Intents.release()
in your teardown
Answered By - Be_Negative
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.