I have been trying to move my Robolectic test cases to Android X Test. I've followed the documentation but unable to launch the activity through Activity Scenario Launch API.
https://developer.android.com/reference/androidx/test/core/app/ActivityScenario
http://robolectric.org/androidx_test
protected void setupActivity() {
ActivityScenario<VisitorExemptionActivity> scenario = ActivityScenario.launch(VisitorExemptionActivity.class);
scenario.moveToState(Lifecycle.State.CREATED);// Activity destroyed before reaching to this point.
}
Above code does not call any android life cycle except onStart , throw following exception and destroyed the activity straight away.
java.lang.IllegalStateException: Cannot move to state "CREATED" since the Activity has been destroyed already
When I tried the same code with Robolectric. It work fine and call all life Cycle. oncreate , onstart and onResume.
protected void setupActivity() {
activityController = Robolectric.buildActivity(VisitorExemptionActivity.class).setup();
activityController.get();
}
Above code call all the life cycle.
Please can you explain to me what I am doing wrong.
Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire