I'll try to answer your last question first:

You are in Activity A, and you use startActivityForResult to start
Activity B. You handle the result of Activity B in
ActivityA.onActivityResult().

How do you test that the actual result is equal to the expected
result? In general, you test the result of a method by creating the
object with all the dependencies set to known values (the fixture),
preferably by injection. Then you call the method with pre-determined
values. Based on the dependencies as the values, you should be able to
predict the answer. You compare this prediction to the object's actual
answer with an assert().

What I think you're *saying*, though, is "How do I create Activity B
(starting it means instantiating an object), find out its result *by
looking inside it*, and then comparing this to the result that comes
back in ActivityA.onActivityResult()?" The answer is: you can't.

You can't instrument more than one class at a time in a single Android
test case class, so you can't test more than one Activity at a time.
Neither ActivityUnitTestCase nor ActivityInstrumentationTestCase2 are
designed to test more than one Activity at a time.

This is by design. Both ActivityUnitTestCase and
ActivityInstrumentationTestCase2 are (IMHO) "pseudo-unit" test
cases.They're both meant to test the methods of one object at a time,
so they're not at the level of Selenium (or it's Android spin-off,
Robotium). On the other hand, they have to run within the Android
environment, so they're not really unit tests. Nevertheless, you
should use the unit test rubric with them: make each test method a
single path through a single Activity method.

To test the interaction between Activities, you probably have to use
Robotium/Selenium or write your own test harness.

On Dec 14, 12:29 am, Etienne <[email protected]> wrote:
> I have created an app that sends intents among multiple activities.
> After doing some research i have found that the ActivityUnitTestCase
> class is designed for unit testing while the
> ActivityInstrumentationTestCase2 is designed for functional testing. I
> understand the use of methods such as setUp(), tearDown(), and
> testPreconditions(). However i am having a little difficulty in trying
> to figure out what type of user-defined-tests to create in the previously
> mentioned classes. I know that there are a few methods that cannot be
> called in certain classes.
>
> To be more specific, if i am in activity A and i click a button then
> it calls startActivityForResult() which starts activity B. I then send
> an intent back to activity A which is handled in the
> onActivityResult() method. How can i test that the actual result in
> onActivityResult() is equal to the expected result?
>
> Is there some sort of mock dependency for interaction between multiple
> activities?
> And if so how do you create mock dependencies?
>
> I have been looking extensively for any kind of examples that would
> help clear up this confusion. I have seen the Demo APIs on the
> developer.android.com
> website but they are rather limited.  If anyone could provide any assistance
> i
> would greatly appreciate it.

-- 
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