I am unit testing the activities in an application. The first activity
test runs fine and everything passes. The second test fails at
getActivity() returning a NPE.
I am assuming that since this is unit testing that getActivity()
should launch the activity even if this activity is reliant on a
previous activity to start it. Any ideas?

//This code works, the activity launches and is tested
@Override
        protected void setUp() throws Exception{
                super.setUp();
                setActivityInitialTouchMode(false);
                mActivity = getActivity();
                mStartButton = (Button)
mActivity.findViewById(com.drayagerecorder.R.id.ButtonStart);
                mStopButton = (Button)
mActivity.findViewById(com.drayagerecorder.R.id.ButtonStop);
                mEditTextTripName = (EditText)
mActivity.findViewById(com.drayagerecorder.R.id.EditTextTripName);
        }

//This code fails and returns a NPE
@Override
        protected void setUp() throws Exception{
                super.setUp();
                Log.i(tag, "Setup");
                setActivityInitialTouchMode(false);
                Log.i(tag, "TouchMode");
                oActivity = getActivity();
                Log.i(tag, "getActivity");
                oSpinner =
                        (Spinner) oActivity.findViewById(
                                        com.drayagerecorder.R.id.origin);
                oOriginData = oSpinner.getAdapter();
                dSpinner =
                        (Spinner) oActivity.findViewById(
                                        com.drayagerecorder.R.id.destination);
                dDestinationData = dSpinner.getAdapter();
                tSpinner =
                        (Spinner) oActivity.findViewById(
                                        com.drayagerecorder.R.id.triptype);
                tTripTypeData = tSpinner.getAdapter();
        }

//The log shows that it fails at getActivity(). I am assuming that
since this is unit testing that getActivity() should launch the
activity even if this activity is //reliant on a previous activity to
start it

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

Reply via email to