The last post explored how to enable Maven builds in a standard Android Eclipse project. This post will show how to enable the test project to be built with Maven.
It will be a bit simpler to enable Maven builds in the test project since we will not need to do any of the prep work. The only thing required is to create a pom file for the test project:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<name>Your Test Android project Maven Enabled</name>
This pom is similar to the pom in the main project but has two more dependencies. They are both pointing to the main project, one to the apk and one to the jar file. The dependency to the jar file is to enable the compiler to find your java classes from the main project. The dependency to the apk is to enable the android maven plugin to find the apk that it will run the tests against on the device or emulator when executing.
The android maven plugin can now run the tests using instrumentation, just like Eclipse does, as long as an emulator or Android device is connected. It uses the same underlying tools.
In order to execute the test the main project needs to be built and installed into the local Maven repository. This is done with the mvn install command in the main projects root folder. When the main project have been installed the same command, mvn install, will build and execute the tests when executed from within the test projects root.
Next post will explain how to create a project hierarchy that makes it possible to build and test the two projects with one command.