I'm following the tutorial found at
http://developer.android.com/resources/tutorials/testing/activity_test.html
to learn how to test on the Android. I'm noticing some weirdness and I
can't find any explanations yet online. So I'm hoping someone here can
help me understand this.

I wrote the method testStateDestroy(). Here's the code:

public void testStateDestroy()
    {
        mActivity.setSpinnerPosition(TEST_STATE_DESTROY_POSITION);
        mActivity.setSpinnerSelection(TEST_STATE_DESTROY_SELECTION);

        mActivity.finish();

        boolean flag = mActivity.isFinishing();
        mActivity = null;
        System.gc();

        mActivity = this.getActivity();

        int currentPosition = mActivity.getSpinnerPosition();
        String currentSelection = mActivity.getSpinnerSelection();

        assertEquals(TEST_STATE_DESTROY_POSITION, currentPosition);
        assertEquals(TEST_STATE_DESTROY_SELECTION, currentSelection);
    }

The setUp() method calls mActivity.getActivity() which starts the
Spinner app up. So far so good. In this method, after setting the
spinner selection, I call finish(). The app goes away. I capture the
isFinishing() flag and it is indeed true. I set mActivity to null and
ask the GC kindly to do a pass. It may or may not, but let's give it a
shot. Then I call getActivity() again. The application does NOT start
up...I'm still at the Android start screen. Yet I have a valid
activity object because the following lines of code that get the
position and selection of the spinner work and the asserts pass.

Okay, so in debug, after setUp calls getActivity, I use the emulator
to change the selection of the spinner to something else. I enter this
method and I can see the selection changes. The same behavior
ensues...no app shows up after calling getActivity(), but the values
retrieved are the right ones which were set before calling finish().

As a side note, the tutorial asks to include a testPreconditions()
method. This method never gets called even though the tutorial states
that it will be called once per test suite. So that's another issue
that I'm noticing.

All the code I've written comes straight from the tutorials except the
line to set mActivity to null and the call to System.gc, which have no
real effect here. If I remove these lines of code I see the same
behavior.

Does anyone have any insight into what's going on with the activities
and the testPreconditions() method? Thanks!

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to