Unit tests for activities

Please let me know how I can write unit tests for activities in an Android application.
The important thing is that how do I simulate consecutive activities. For example, let's assume I have 3 activities A, B and C. How can I test the state of Activity B, based on what the user has done in Activity A and Activity B?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dshrenikAuthor Commented:
Thanks for the links!

I did try those tutorials, but I felt that the content in those links were insufficient to do the kind of testing I described in my question.

Dejan PažinHead of SW DevelopmentCommented:

The framework allows you to get the reference to the objects inside your application.  That is all you need to get a result of the input and use it in the next activity.

See this example:


This is the important part, where it shows how to get the reference:

  protected void setUp() throws Exception {
      mInstrumentation = getInstrumentation();

      mActivity = getActivity(); // get a references to the app under test

       * Get a reference to the main widget of the app under test, a Spinner
      mSpinner = (Spinner) mActivity.findViewById(com.android.demo.myactivity.R.id.Spinner01);

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dshrenikAuthor Commented:
mActivity = getActivity(); => this gets me a reference to the current activity right?

What if I want to click a button in this activity, which creates an activity B. How do I get a reference to activity B?

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.