Hi all!

As I promised more than a year ago ;) I'm going to continue the small tutorial about testing on Android. During this year the testing on android has evolved a little bit and now we can see projects, like robotium, that, although they have some errors and features not (well) covered, helps you a lot in the testing process. Said that, let's start!

The first step to test an android application (apart from having the code of the android application, of course) is create a test project. For that we are going to use the command line, mainly because, although you can use very complete graphical editors that helps you to do much of the process automatically, I think it's important to know where the things come from and why the things work in that way. So, the command line to create the test project (as we can check here) is:

$ android create test-project -m <main-path> -n <project-name> -p <test-path>

Where main-path is the path to the project of the application under test, project-name is the name of the test project (not the name of the main project) and test-path is the directory where the test project is going to be located. A test project depends on the android project that is testing, so is going to compile against this project, recompiling (with a little bit of luck) all the source files of the original project that needs to (re)compile, that's why we need to indicate the path of the main project under test.

That also means that a test project is going to test only one application at a time, but it can be updated to change the path of the main project for the case you want to test another project with the same test project (for example, if you have two projects of the same application, one for a free version and other for a premium version, or if you have a base test project that you want to adapt to new applications).

The test project doesn't need to be located in any specific directory, so you can place it wherever you want in your filesystem, but take care if you move the test project and you've defined a relative path to the main project, because you'd need to update it.

If you check the test project just created, you can see that it haves the same directory structure and build file contents as regular Android application project. That's because it's an actual Android application that use the testing and instrumentation framework and depends on other application to run (like an application that use a library).

The test framework is an extension of the JUnit test framework that adds access to the Android system objects to test them, and the instrumentation framework is who actually execute the tests, starting the application at the beginning of each test suite, shutting down the application once the test suite is finished and who runs test by test of each test suite.

Well, that's enough for today. In the next post I'll explain the compilation process of a test project (checking the options at the compilation files) and how to run both on test in particular and all the tests of the test project. In that way you can see the basic structure of a test.

To be continued…