Android testing, basics, running a set of tests automatically

Hello everybody,

Today I will cover a simple, but extremely useful topic – how to run all your Android automated tests 🙂

For example, you have created some classes, which are extending ActivityInstrumentationTestCase2 and you are not satisfied by running this classes one by one, lets assume you want to run all your 100 classes using simple approach or hitting one button and leave the office and do not care how tests are working 🙂

It is very simple, all you need is to create your own TestSuite.

To do that, just add new class:

// Please note all other test classes should be under this package:
// org.example.roottestpackage.*;
// for example: org.example.roottestpackage.myothertestpackage;

package org.example.roottestpackage;

import junit.framework.Test;
import junit.framework.TestSuite;
import android.test.suitebuilder.TestSuiteBuilder;

public class AllTests extends TestSuite {
public static Test suite() {
return new TestSuiteBuilder(AllTests.class).includeAllPackagesUnderHere().build();
}
}

That’s all 🙂 You can run this class as usually by creating Run configuration.
After run Eclipse will put all your classes into the list, and run them.

Please note if test crashes the process of testing application all further tests will be terminated!

Happy auto testing (:

Best regards,
Yahor