Combining Ant and Launchable to get faster CI test feedback

Transform Your CI Process

Key Takeaways

  • The newest profile we've built, Ant.

  • How to connect Launchable to Ant with the Launchable CLI.

  • Now, you can run a subset of a long-running test suite more often.

The Launchable CLI provides a simple, uniform interface between your CI process and the Launchable service.

To make integration even easier, we’ve built profiles into the CLI for popular build and testing tools. These profiles abstract away the nuances of specific languages and test runners so you only have to add a few lines to your build script to get started.

One of these profiles is for Ant. In this post, we’ll show you how to connect Launchable to Ant to train a model and get faster test feedback.

What is Launchable?

Launchable uses machine learning to identify the most important tests to run for a specific code change. This capability lets you run a smaller set of important tests earlier and more frequently in your software development lifecycle, providing faster feedback to developers without compromising quality.

To enable this, you can use the Launchable CLI to connect Launchable to your test runner both to train a machine learning model and to get and run test recommendations supplied by Launchable.

Connecting Launchable to Ant with the Launchable CLI

After installing the Launchable CLI package from PyPI and setting your API key, you’ll need to add three Launchable commands to your build/test pipeline.

First, you need to record a build to tell Launchable the code changes that are being tested. Launchable uses this information to train the machine learning model and to recommend tests to run for those specific changes.

To do this, you add the `record build` command to your CI script. You give the build a name and point the CLI to your Git repository on the CI server (`.`):

launchable record build --name <BUILD NAME> --source src=.

Then, you need to record test results after running tests to train the machine learning model:

launchable record tests --build <BUILD NAME> ant <PATH TO JUNIT XML>

You'll notice that this command uses the same `<BUILD NAME>` value; that's how Launchable learns that these test results relate to the new commits in the build.

Once you’ve started sending test results to train a model, you can start subsetting tests. Over time, the test recommendations will improve as the model learns.

Before running tests, you need to request a dynamic subset of tests from Launchable and pass those to Ant to run them.

You provide the same build name, a target percentage of test duration to run in the subset, and the directories where your tests reside:

launchable subset 
  --build <BUILD NAME> \
  ant <PATH TO SOURCE> > launchable-subset.txt

The subset command outputs a list of recommended tests specifically for that buildto launchable-subset.txt which you then pass into Ant to run. You do this by modifying your build.xml file:

2 …
3 <target name="check-launchable">
4  <available file="launchable-subset.txt" property="launchable"/>
5 </target>
8 <target name="junit" depends="jar,check-launchable">
9  <mkdir dir="${report.dir}"/>
10  <junit printsummary="yes">
11   <classpath>
12     <path refid="classpath"/>
13     <path refid="application"/>
14   </classpath>
17   <formatter type="xml"/>
20   <batchtest fork="yes" todir="${report.dir}">
21    <fileset dir="${src.dir}" >
22     <includesfile name="launchable-subset.txt" if="${launchable}" />
23     <include name="**/*" unless="${launchable}" />
24    </fileset>
25   </batchtest>
26  </junit>
27 </target>
28 …

Then, you run the subset of tests:

ant junit

See for more documentation and examples.

Now you can run a subset of a long running test suite more often. For example, you could run a subset of long running end-to-end UI tests on every git push instead of only after every merge. Or you could subset your pull request tests to get faster feedback, earlier.

Seeking Your Expert Feedback on Our AI-Driven Solution

Quality a focus? Working with nightly, integration or UI tests?
Our AI can help.