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. What is the proper way to close an activity/application?

I started to develope an application.
When I wanted to close the application I clicked on the home screen,
but the app is still playing in the background.
Than I tried to click on the "back" key, but nothing happend, so I've
created a key event listener for the 'back" key, and inside that
method I wrote finish();
Now my app is closing but I think it's still running in the
background, because when I go to "manage applications" I can still see
it in the "running" tab, and if I press it, I see I can click on the
"force close" to actually close the app.

What do I need to do in order to really close the app without leaving
it open (one way or another)?


2. How to dynamically modify xml file in android

Hi ,
 I want to modify an xml file which is in sdcard dynamically.
How can we acheive this in android. I have seen some java code as follows

try {   
        File file = new File("connections.xml");

        //Create instance of DocumentBuilderFactory
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

        //Get the DocumentBuilder
        DocumentBuilder docBuilder = factory.newDocumentBuilder();

        //Using existing XML Document
        Document doc = docBuilder.parse(file);

        //create the root element
        Element root = doc.getDocumentElement();

        //create child element
        Element childElement = doc.createElement("number");

        //Add the attribute to the child

        //set up a transformer
        TransformerFactory transfac = TransformerFactory.newInstance();
        Transformer trans = transfac.newTransformer();

        //create string from xml tree
        StringWriter sw = new StringWriter();
        StreamResult result = new StreamResult(sw);
        DOMSource source = new DOMSource(doc);
        trans.transform(source, result);
        String xmlString = sw.toString();

        OutputStream f0;
        byte buf[] = xmlString.getBytes();
        f0 = new FileOutputStream("connections.xml");
        for(int i=0;i<buf .length;i++) {
        buf = null;
     catch(SAXException e) {
     catch(IOException e) {
     catch(ParserConfigurationException e) {
     catch(TransformerConfigurationException e) {
     catch(TransformerException e) {

But The TransformerFactory class is not avalible in android sdk.
How can we handle above code
Any help please,
Thanks in advance


3. How to fix a 鈥渏ava.lang.O utOfMemoryError: bitmap size exceeds VM budget 鈥?error on android

4. Can 9 patches have more than marked region or not?

5. libwebcore size in debug build

6. how to make sure my Service is restarted?

7. Strange instance of "app not responding" error