View Source

{excerpt}Explains a temporary solution how to use the Testability Explorer in Maven 2 projects.  {excerpt}

h1. Background

[Testability Explorer|http://code.google.com/p/testability-explorer/] is an open-source tool that identifies hard-to-test Java code. Right now, you can run the program from the Command Line or using the [Ant Task|http://code.google.com/p/testability-explorer/wiki/AntTask]. There is no Maven 2 plugin available at the moment. You have to use the {{maven-antrun-plugin}} for the time being. However, there is one big problem. The Testability Explorer JAR files are not available yet in any Maven 2 repository. This page offers a temporary solution for this problem until the JAR files become available in any public Maven 2 repository.

h1. Installing the JAR files to local Maven repo

In order to use the {{maven-antrun-plugin}} with the {{com.google.ant.TestabilityTask}}, you have to add two dependencies into your Maven 2 pom.xml under the dependencies section.
{code:xml}
<dependency>
<groupId>com.google.code.testability-explorer</groupId>
<artifactId>testability-explorer</artifactId>
<version>1.3</version>
</dependency>

<dependency>
<groupId>com.google.code.testability-explorer</groupId>
<artifactId>ant-testability-explorer</artifactId>
<version>1.3</version>
</dependency>
{code}
As said before, the JAR files are not available in any public repository. You have to add them manually into your local repository. Run the Maven install commands:
{code:none}
mvn install:install-file -Dfile=[path to]/testability-explorer-1.3.0-r275.jar \
-DgroupId=com.google.code.testability-explorer -DartifactId=testability-explorer -Dversion=1.3 \
-Dpackaging=jar -DcreateChecksum=true

mvn install:install-file -Dfile=[path to]/ant-testability-explorer-1.3.0-r275.jar \
-DgroupId=com.google.code.testability-explorer -DartifactId=ant-testability-explorer -Dversion=1.3 \
-Dpackaging=jar -DcreateChecksum=true
{code}
You are now ready to use the Testability Explorer in a Maven 2 powered project locally.

h1. Running the Ant Task from Maven

Now that you have the JAR files available locally, you can use the {{maven-antrun-plugin}} to run the Testability Explorer during builds. Go to the build section of your pom.xml and add the following plugin (if you do not have a build section in your pom.xml, you have to create {{<build>}} and {{<plugins>}} first).
{code:xml}
<build>
<plugins>
...

<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>Testability Explorer</id>
<phase>test</phase>
<configuration>
<tasks>
<path id="ant.classpath">
<path refid="maven.runtime.classpath" />
</path>

<echo message="Running Testability Explorer" />

<property name="testability.report.dir" value="target/reports/testability" />
<delete dir="${testability.report.dir}" />
<mkdir dir="${testability.report.dir}" />

<taskdef name="testability" classname="com.google.ant.TestabilityTask">
<classpath refid="maven.runtime.classpath" />
</taskdef>
<testability filter="my.package" resultfile="${testability.report.dir}/results.xml" print="xml">
<classpath refid="maven.runtime.classpath" />
</testability>

<echo message="Done. Reports can be found in ${testability.report.dir}/results.xml" />
</tasks>

</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
{code}
This will execute the {{com.google.ant.TestabilityTask}} during the test phase of a Maven 2 run, ie. if you run {{mvn test}}. Note: in the XML snippet above you have to replace {{my.package}} with your own Java package that you want to have tested.

h1. Prospects

The suggested solution is far from optimal. As the JAR files will become available in a public Maven 2 repository, you will not have to copy them manually into you local repository. Sooner or later, there will also be am official Maven 2 plugin, so that the {{maven-antrun-plugin}} will not be required anymore.