Run your API tests on Travis CI
This tutorial assumes you know how to launch Restlet Client tests from CLI. If you don't know, please have a look at the documentation first.
Now let's run our API tests on Travis CI! Travis CI is a popular tool helping development teams to continuously building and delivering apps with confidence. It’s free for open-source projects. Just login with your Github account and you’re set.
Running your scenarios on Travis CI
First thing to do in order to run your scenario on Travis CI is to push it to a Github repository. Make sure you push the 2 test files:
- the JSON file containing your scenario
- the pom.xml configuration file
Note: Restlet Client now has a GitHub integration to help you push your tests files to GitHub in a whim. You can learn more about this feature here.
Second step is to go to your profile page on travis-ci.org, find your Github repository and switch it on:
The third and final step is to create a .travis.yml file for Travis configuration. Let’s start with a simple configuration:
language: java jdk: oraclejdk8 install: true # skipping the default Travis install step script: - mvn test
After pushing your .travis.yml file to your Github repository, you should see the build running on Travis-CI:
From now on, each time you push to your Github repository, a build will be triggered on Travis CI, and will run your test scenarios!
Setting up your license key
Test scenario automation through Maven is a paying feature, so you’ll be asked to enter your license key. Your license key is private to you and should not be published on a Github repository. A simple way to securely manage your key is to add it as an environment variable in Travis CI settings :
You can find your license key on the Restlet Client billing page. You’ll then be able to access your key in your build script and pass it to Maven:
script: - mvn test -Dlicense_key=$LICENSE_KEY
This argument can then be used in your pom.xml configuration:
Another valid option would be to store it as an
Automating scenario execution in Travis CI
Travis CI offers the ability to schedule job executions . It can be very practical if your team is doing nightly deployment. That way you’ll be ensuring that the latest version of your API, deployed each night on a staging environment, does not break your API contract.
It’s also good to know that you can trigger a Travis build by calling the Travis API .