Android automated test for activity destroyed and re-created -


We are trying to test the behavior of our application because it has different lifecycle states (active, paused, stopped, Destroyed) and then in those states, on the way back from the destroyed kingdom.

We have the problem that when instrumentation.callActivityOnCreate (testActivity, New Bundle)) is called,

04-16 15 : 40: 20.840 8989-898 / 9? E / AndroidRuntimeï¹ ?? Fatal exception: main activity in java.lang.IllegalStateException: android.app.FragmentManagerImpl.moveToState (FragmentManager.java:1044) Android.f.fragmentManagerAmple.mouthoostat (FragmentmanGear.Javotel39) Android.f.fragmentmanagerimple.DispatchCreator (FragmentManager.java : 1835) android.app.activity.onCreate (Activity: Java: 9 16) Android. Support.v4.app.FragmentActivity.onCreate (FragmentActivity.java204) at com.test Test activity .onCreate (Test.activation.java *) at android.app.Activity.performCreate at (activity.java / 158) android.app.Instrumentation.callActivityOnCreate (Instrumentation.java:1081) com.test.TestActivityInstrumentationTest $ 3 Callback (handler.java: 747) android.os.Handler.dispatchMessage at $ syncRunnable.run (Instrumentation.java:1684) android.os.Handler.handle on .run (TestActivityInstrumentationTest.java: 25) on Android.app. (Handler.java:92) on Android.os.Looper.loop (Looper.java.11) and Android.AP.ActivateTrade.Mine (ActivityTrad.Java Teacher 152) at Java.lang.reflect.Method.invoke va .lang.ref.method.invokeNative (Native Methods) com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java : 793)) com.android.internal.os.ZygoteInit.main (ZygoteInit.java) 60) on Dalvik.system.NativeStart.main (Basic method)

The test code is below Import android.app.activity; Import android.f. science; Importroid.os.Bundle; Import android.test.ActivityInstrumentationTestCase2; Import com.test.TestActivity; Public Class TestActivityInstrumentationTest Activity InstrumentationTestCase2 & lt; TestActivity & gt; {Public TestActivityInstrumentationTest () {Super TestActivity.class}; } Public Zero Test VectorOntrusted and Starred () {Final Test Activity Test Activate = getActivity (); Last Instrumentation Instrumentation = getInstrumentation (); Instrumentation. RonanManSync (New Runnabel) {@ Override Public Wide Run () {Instrumentation. Call activation onstoy (test activity);}}); Instrumentation. RannOnManSync (New Runnabal) ({Override Public Wide Run) (Instrumentation: Activity Integrity, New Bundle)}}}); }}

Test activity

  Import android.support.v4.app.FragmentActivity; Public Sector Test Activity Fraud Activity (Crusade Protected by Bundles) on Public Zero (Superstructure) Contents (Saved Instantstate);  

div class = "post-text" itemprop = "text">

Add a setUp () to start your activity and conduct the exam to finish the tearing () I'm destroying activities (I think this is what you want to do):

  / ** * Example from Solo: providing ways to call the Android user interface Does. * * / Protected single single; / ** * Activity under trial * / Test activity activity; / * * (Non-JavaWadoc) * SEE android.test.ActivityInstrumentationTestCase2 # setUp () * / @ Override Protected Zero Set Up () Exception {activity = getActivity ()) throws; // If you are using robotium: single = new solo (getInstrumentation ()), getActivity ()); } @ Override Public Wide Tire Duown () throws exception {// Teardown ()) is run after a test case is over. // Finish Open Activitia () will terminate all the activities opened during the execution of the exam. Solo.finishOpenedActivities (); super.teardown (); }   

Test if you receive an activity example at the beginning of each trial:

  Public Zero TestVectorOntrusted and Starred () {// Valid The assertNotNull activity has been returned to ensure handles; }   

When you want to test your ontoroy, try this code:

  instrumentation.runOnMainSync {new Runnabel} {@Override Public Zero Run () {// to achieve activity to achieve activity = getActivity (); // Check that you are actually claiming a reference, the nautical (activity); // and here you are the activity instrumentation. Call ActiveAct (activity, new bundle));}});    

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -