Three steps to subset tests with Launchable & Gradle
Three steps to add Launchable to your Gradle build process for faster test feedback.
Key Takeaways
Predictive Test Selection speeds up Gradle build processes with smarter, faster test runs.
Step-by-step instructions to start using Launchable with Gradle
Launchable uses machine learning to identify and recommend the most important tests to run for a specific code change. This is called predictive test selection. This capability allows you to run a smaller set of important tests earlier and more frequently in your software development lifecycle, providing much faster testing feedback to developers without compromising quality.
To make integration really simple, we’ve built profiles into the Launchable 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.
One of these profiles is for Gradle, an extremely popular build tool for the Java ecosystem. In this post, we’ll show you how to add Launchable to your Gradle build process to get faster test feedback.
(If you're interested in using Launchable with other test frameworks or programming languages, see integrations.)
Step 1: Record a build
Before getting started, install the Launchable package from PyPI and set up your API key within the context of your pipeline.
The first step of integrating Launchable is to record a build. Recording a build tells Launchable what has changed in the version of the software being tested. Launchable uses this information both to train a machine learning model and to recommend tests to run for those specific changes.
To do this, before building software, you run the `launchable record build`command. You give the build a name and point the CLI to your Git repository on disk:
launchable record build --name <BUILD NAME> --source .
Step 2: Request a subset of tests
Before running tests, you need to request a subset of tests from Launchable and pass those tests to Gradle 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. The subset command outputs a list of tests to launchable-subset.txt that you can then pass into Gradle to run them.
launchable subset \
--build <BUILD NAME> \
--target <TARGET> \
gradle project1/src/test/java > launchable-subset.txt
gradle test $(cat launchable-subset.txt)
Step 3: Record test results
Finally, you need to record test results so Launchable can continually train the machine learning model:
# run the tests however you normally do
gradle test $(cat launchable-subset.txt)
launchable record tests --build <BUILD NAME> gradle ./build/test-results/test/
(See docs.launchableinc.com 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.
Interested in getting started with Launchable? Sign up for a free trial and join our Discord server. As you can see, it’s really easy to get started!