-
Notifications
You must be signed in to change notification settings - Fork 43
Integration with Travis
Travis is a popular Continuous Integration service for testing GitHub hosted projets.
The following example taken from the XSpec project illustrates how to run XSpec tests in a Travis build for a project hosted on GitHub.
-
Create the following
.travis.yml
:before_script: - git clone -b master https://github.com/cirulls/xspec.git /tmp/xspec - export SAXON_CP=/tmp/xspec/saxon9he.jar script: - cd test - echo "execute XSpec unit tests" - ./run-xspec-tests.sh
The commands in
before_script
clone the XSpec project from GitHub, store it intmp/xpec
and set up the path for Saxon. The commands inscript
navigate into thetest
directory and run a shell script that executes all the XSpec test suite. Modify the test directory to the location where your XSpec tests are stored. -
Create the shell script
run-xspec-tests.sh
that runs all the XSpec tests in thetest
directory (modify the relative path../bin/xspec.sh
in the second line if needed):for xspectest in *.xspec; do ../bin/xspec.sh $xspectest &> result.log; if grep -q ".*failed:\s[1-9]" result.log || grep -q "*\sError\srunning\sthe\stest\ssuite" result.log; then echo "$xspectest failed" && exit 1; else echo "ok $xspectest"; fi done
This shell script outputs the name of the successful XSpec test executed. If an XSpec fails, the script stops and provides the name of failing test with the error message stored in
result.log
-
Push to your GitHub repository the following files:
-
.travis.yml
: this must be pushed to the root of the GitHub repository you want to test. You can have different.travis.yml
for different branches. -
run-xspec-tests.sh
: ideally this should be pushed to the same directory when your XSpec tests are located. - your XSpec tests
-
Here is an output of a successful build with XSpec tests on Travis: