Android Functional Testing (testing multiple activities)

by Rick » Fri, 17 Apr 2009 23:48:08 GMT

Sponsored Links
 I've been exploring the Android test package and I'm very confused on
how to implement functional testing for endpoint-to-endpoint.

Consider the example below, I have 4 activities:
1. A Contact List Activity
2. A View Contact Activity
3. An Add/Edit Contact Activity
4. A Sync Contact List activity

I want to automate a few tests that will go through multiple test
cases simulating a user experience:
the add contact activity,
entering data, saving it, going back to the list activity, and
verifying the new contact was saved properly.

As I understand it, ActivityInstrumentationTestCase<T extends
Activity> and ActivityUnitTestCase<T extends Activity>, are only
useful for testing single activity functionality.

But what if I need to switch between 2 or more activities inside a
single functional test case?

Any help would be greatly appreciated.


Android Functional Testing (testing multiple activities)

by z » Sat, 18 Apr 2009 01:41:37 GMT



Sponsored Links

Android Functional Testing (testing multiple activities)

by Rick » Wed, 29 Apr 2009 00:36:33 GMT

 Android functional testing across multiple activities:

Since no one has really shown how to do this, and Android really only
shows us testing a single activity,
testing more complex applications will need cross-activity testing.
How to do it?

1. Use InstrumentationTestCase
2. Use an ActivityManager to maintain the scope of the application,
allowing you to grab the activity you want.
3. Use Instrumentation to put the application in the desired state
4. Most importantly, make sure to clean up after your test, other wise
it will hang.

All android testing runs through the setUp and TearDown before each
test. So if you have a test class with 5 tests,
it will run through the set up and tear down before each test.

You might be able to get around this by implement the @BeforeClass and
@AfterClass for a global setUp and TearDown
that can be spread across the test suite, I haven't explored that yet.
Hope this helps anyone looking for this.


Android Functional Testing (testing multiple activities)

by zlu » Wed, 29 Apr 2009 01:51:58 GMT


Thanks so much for posting your findings. They are helpful.


On Apr 28, 9:36am, Rick <> wrote:

Other Threads

1. Detect TAB key?

I would like to intercept the tab key in an EditText.  I derived a new
class from EditText and implemented the OnKeyListener interface.  I
look for event.getAction() == KeyEvent.ACTION_DOWN && keyCode ==
KeyEvent.KEYCODE_TAB, but here is what happens:

user presses alt -> action down / keycode alt
user releasees alt -> action up / keycode alt
user presses q -> action down / keycode q
user releases q -> action up / keycode q

So, a tab character is never intercepted by OnKeyListener...yet a tab
will ultimately be deliver to the EditText, so I failed to intercept
it.  Next thing I did was implement my OnKeyListener differently.
Instead of look for key down and keycode tab I look for key down,
event alt pressed, and keycode q, as in:

user pressed alt -> action down / keycode alt
user presses q -> action down / event.altpressed true / keycode q
user releases q
user releases alt

This implementation successfully intercepts an action where the user
presses and holds alt while pressing q, which would ordinarily deliver
a tab to the EditText, so that's great, that worked, I intercepted the

...but there's two problems with relying on this approach (looking for
key down, alt pressed, and keycode q).  First, it still lets the other
kind of tab through to the EditText and I want to intercept those tabs
too.  Second, I assume there is no guarantee that on other hardware
besides the G1 that the tab will correspond to an alt-q in the first
place, so hard-coding such a test seems inappropriate.

What is the solution to this problem?

Thank you.


2. Dealing with Microsoft Exchange support

I haven't yet got a G1 but as I understand it doesn't come with
support for Microsoft's Exchange Server.

Since Microsoft requires licensing of the protocols involved, it seems
that this item is outside of what can be done in Open Source. I.e.
each handset vendor must license such software from an ISV.

Is this correct?

Wasn't exactly this situation that caused the EU to fine Microsoft
some $400M?

3. Merge file

4. google Calendar API test problem

5. Getting numbers from a single contact

6. How to implement a magnifier like the input method in iPhone ?

7. Topics on Electronics