Jenkins, TestLink and GTest in 5 minutes (or so)
This is a 5 minutes guide on creating a job for a C++ project in Jenkins with GoogleTest and reporting the test results back to TestLink, with testlink-plugin.
The test project with GoogleTest
For this simple guide we will use the samples that come with GTest TAP Listener. You can get the code from GitHub with git clone git://github.com/kinow/gtest-tap-listener.git
. Take a look at gtest-tap-listener/samples/src/
, there you will find two C++ files: gtest_main.cc
and gtest_testHelloWorld.cc
.
gtest_main.cc
has the main function, and executes the test suite. And gtest_testHelloWorld.cc
has the test cases and tests. Take note of the test case and tests names.
Configure TestLink
OK. Now create a project in TestLink or use an existing one. And the same goes for Test Suite, Test Cases and Test Plan. The only think you have to take care is to add a custom field, and use the GTest test case names. Take a look at the picture below to have a better idea.
If you have trouble configuring TestLink, take a look at this chapter of Jenkins TestLink Plug-in Tutorial.
Configure Jenkins
Almost there, now the only step: configure Jenkins! Install Jenkins TestLink Plug-in, go to the global configuration and add your TestLink installation. Don’t forget the devKey in order to let Jenkins access TestLink.
Now create a job, configure Git Plugin to get the code from git://github.com/kinow/gtest-tap-listener.git
. Add a build step to Invoke TestLink
. There will be three sections: TestLink Configuration, Test Execution and Result Seeking Strategy.
Under TestLink Configuration, fill in your TestLink configuration, test project, test plan, any build name
of your choice (you can try gtest-build-$BUILD_ID ;) and the name (not the label) of your custom field.
In Test Execution, a make --directory=samples
will build the project, and then finally you can run
./gtest-tap-listener-samples
. This executes GTest using a TAP listener to output TAP.
As your test execution generated some TAP files, let’s use a Result Seeking Strategy
that reads TAP files:
TAP file name. Just use samples/*.tap
as Include Pattern
and put your custom field
name as Key Custom Field
.
Run your build, and voilà :-)
As an exercise, you can try to use Jenkins TestLink Plug-in to display your TAP results. This blog post has been created after JENKINS-15486.
Other resources
Categories: Blog
Tags: Jenkins, Testlink, C++, Software Quality