Wednesday, September 21, 2011

Android testing with Maven build management


This post may be can help you to quick start for android testing as with maven


As we know Maven can build the android projects + runs the Instrumentation tests. Like Building, Deploying, Testing and Advanced level reporting.. And also having a very good folder structure to keep all the source test classes and run into the several devices

Using by maven you easily maintain extensive unit tests and your activity tests, service tests, content providers tests and all in to one place...


A sample Maven Android Test Directory 


..app> mvn install

When you run this target, Firstly it can compile the all the source class files Secondly, it  can run only the unit test cases  and generate the reports.

..app-Instrumentation> mvn install
This target compiles the automation test cases and generates the test .apk file

Robotium using by Maven  
You can also write automation UI test cases by using Robotium for automation testing. There is no need to attach Robotium jar file. This jar file will take from repositories itself. All the dependencies will automatically download. You can also execute same test suite in to the number of devices also.

Advantages :
1. Run the test cases by using single command from the command prompt
2. Multiple device support for test execution
3. Automatically generate the test reports in the XML format for each and every device which are connected
4. No need to worry about signature(signing) 

Dis Advantages:
1. The build system can depend on the source code. So without application source code it is not possible to run your automation test cases... 

For use to get robotium in your test project , You need to add the followed dependency  


Test Suite building

import android.test.suitebuilder.TestSuiteBuilder;
import junit.framework.Test;
import junit.framework.TestSuite;
public class AllTests extends TestSuite {
    public static Test suite() {
        return new TestSuiteBuilder(AllTests.class) .includeAllPackagesUnderHere() .build();
      }}

Running tests

If you use a test runner other than InstrumentationTestRunner, you must change the element to point to the class you want to use.

instrumentation android:name="android.test.InstrumentationTestRunner"
                       android:targetPackage="com.pkg_name "

Once the Instrumentation starts, android system classes can load and start the test package, If any other processes are running it can kill all the processes and run an instance of the application under test, and then it can load a new instance of the application under test.

…app-Instrumentation> mvn android:deploy 
This target can run the Instrumentation can start and can run with the device or emulator 

Multiple device support for deploying and getting the test results for Test reporting 

If you run a test in Eclipse with ADT, the results are displayed in a new JUnit view pane only and again at end of the test, you have to export the results in to the XML files…

So it is very hard to run and saving the reports. and also time consuming

In this case maven can the run unit tests and instrumentation tests in the number of devices and finally it can generate the reports into the XML files and save the reports for each device or emulator


A sample automation report generated by Maven run time environment



In this case I have attached one real LG Android device, 2 emulators and the XML file reports has generated with prefix name as a “TEST-……..”

You can also give the name of the devices to only run all emulators or only all devices or only a specific device
mvn android:deploy -Dandroid.device=emulator-5554
mvn android:deploy -Dandroid.device=emulator-5556
mvn android:deploy -Dandroid.device=someAvdName
mvn android:deploy -Dandroid.device=8283838993839393AESA
mvn android:deploy -Dandroid.device=deviceSerialNumber 


Followed links may be help you to get know more details about this 


No comments:

Post a Comment