Book
Book
Bruno P. Kinoshita
Abstract
The Jenkins TestLink Plug-in Tutorial is intended to provide a better understanding on how to use the plug-in to integrate
Jenkins and TestLink. It is an Open Source project, so contributions and suggestions are welcome.
Jenkins TestLink Plug-in Tutorial
Table of Contents
1. An Introduction to Jenkins ................................................................................................................ 1
2. An Introduction to TestLink ............................................................................................................. 3
3. Jenkins and TestLink Integration ....................................................................................................... 5
4. TestLink Configuration ..................................................................................................................... 6
4.1. Installing TestLink ................................................................................................................. 6
4.2. Creating a Test Project .......................................................................................................... 9
4.3. Creating and assigning a Custom Field ................................................................................. 11
4.4. Specifying Test Suite and Test Cases .................................................................................... 13
4.5. Create a Test Plan and add the Test Cases ............................................................................ 16
5. Jenkins Configuration ..................................................................................................................... 19
5.1. Installing Jenkins ................................................................................................................. 19
5.2. Installing and configuring Jenkins TestLink Plug-in ............................................................... 19
5.3. Creating a job in Jenkins ...................................................................................................... 21
TestLink Configuration ....................................................................................................... 22
Test Execution ................................................................................................................... 23
Result Seeking Strategy ...................................................................................................... 24
5.4. Explaining the Job configuration parameters ......................................................................... 25
TestLink Version ................................................................................................................ 25
Test Project Name .............................................................................................................. 25
Test Plan name .................................................................................................................. 25
Build Name ........................................................................................................................ 25
Single Build Steps .............................................................................................................. 25
Iterative Test Build Steps .................................................................................................... 25
Test Result Seeking Strategies ............................................................................................ 25
Include pattern ................................................................................................................... 26
Key Custom Field .............................................................................................................. 26
Attach TestNG XML .......................................................................................................... 26
Mark skipped test as Blocked ............................................................................................. 26
Environment variables ........................................................................................................ 26
6. Executing Automated Test Cases .................................................................................................... 28
7. Result Seeking Strategies ................................................................................................................ 31
7.1. JUnit ................................................................................................................................... 31
JUnit case name ................................................................................................................. 31
JUnit class name ................................................................................................................ 31
JUnit method name ............................................................................................................ 31
JUnit suite name ................................................................................................................ 31
7.2. TestNG ............................................................................................................................... 31
TestNG class name ............................................................................................................. 32
TestNG method name ......................................................................................................... 32
TestNG suite name ............................................................................................................. 32
7.3. TAP - Test Anything Protocol .............................................................................................. 32
TAP file name ................................................................................................................... 32
8. Advantages of using Jenkins TestLink Plug-in ................................................................................. 33
9. Appendix ....................................................................................................................................... 34
9.1. Adding attachments to your test results ................................................................................. 34
9.2. Using Platforms ................................................................................................................... 34
9.3. Plug-in behavior in distributed environments ......................................................................... 35
9.4. How to use the plug-in with SSL or basic authentication? ...................................................... 35
Bibliography ...................................................................................................................................... 36
1. An Introduction to Jenkins
Jenkins (née Hudson) is a continuous integration server written in Java. It can be downloaded from http://
www.jenkins-ci.org [http://www.jenkins-ci.org] as an executable war. It means that you can run it with java -
jar jenkins.war. Jenkins comes with an embedded Servlet Container (Winstone) but you also have the option
to deploy the war to an application server like Tomcat, Jetty, JBoss, etc. Jenkins does not use any database to
store its configuration. Jenkins uses XStream to save data as XML files.
With Jenkins you can create, monitor and schedule jobs. There are plug-ins for almost anything that you may
think about, from different SCMs (git, mercury, SVN, CVS) to plug-ins for integrating your Jenkins with
Selenium, Gerrit, TestLink and other tools.
Here is a summarized list of Jenkins features that is available in Jenkins Wiki [http://wiki.jenkins-ci.org/
display/JENKINS/TestLink+Plugin]:
1. Easy installation
2. Easy configuration
4. Permanent links
5. RSS/E-mail/IM Integration
6. After-the-fact-tagging
8. Distributed builds
9. File fingerprinting
10.Plugin Support
For this guide we suggest you to use the LTS (long term support) version of Jenkins. At the moment that this
guide is being written, the current version is 1.424.6. However it is very likely that what you will learn here
will work with newer versions of Jenkins. Jenkins development team does a great job not only developing cool
features, but also keeping backward compatibility between versions.
Jenkins is licensed under the MIT License and its code is hosted at GitHub - http://github.com/jenkinsci [http://
github.com/jenkinsci].
2. An Introduction to TestLink
TestLink is an open source test management tool written in PHP. In order to install TestLink you will need
a HTTP server with PHP 5 and a database. The databases currently supported by TestLink out of the box
are MySQL, Postgre SQL and MS SQL, although there are users that managed to use Oracle too. You can
download it from http://www.teamst.org [http://www.teamst.org].
In TestLink you have, among other features, Test Plans, Requirement management, Baselines, Custom Fields,
Test Suite with Test Cases and Reporting. For external access, there is an XML-RPC API available (it is not
enabled by default). Other two nice features in TestLink are the versioning of the some entities, like Test Case
and Requirements, and the ability to import and export data in different formats.
There are bindings for the TestLink XML-RPC API available for Java, Perl, PHP, Ruby and other programming
languages. The integration between Jenkins and TestLink is done using TestLink Java API - http://
testlinkjavaapi.sourceforge.net [http://testlinkjavaapi.sourceforge.net].
At the moment that this guide is being written the latest version of TestLink is 1.9.3. While the Jenkins version
is not a big issue for this integration, the same cannot be said about TestLink. This guide is intended for
Testlink 1.9.3 XML-RPC API. In case there are other versions available at the moment that you are reading
TestLink is licensed under the GPL License and its code is hosted at gitorious - http://www.gitorious.org/
testlink-ga/testlink-code [http://www.gitorious.org/testlink-ga/testlink-code].
This way, while Jenkins handles the execution of jobs and tasks such as downloading source code from an
SCM, TestLink maintains the structure of your tests, as well as other assets such as Test Plan, Custom Fields,
Reports and Baselines.
We will see how to configure our environment for this integration throughout the next chapters. While it is
good to have a written explanation on how this integration works, probably it is a lot easier to understand
how it works with a hands-on. The rest of this guide explains how to configure Jenkins and TestLink to run
automated tests from a sample test project. This test project is a Java project that uses Maven and TestNG and
you can download the source code from https://github.com/tupilabs/jenkins-testlink-plugin-tutorial [https://
github.com/tupilabs/jenkins-testlink-plugin-tutorial] (as well as the DocBook source for this book).
The current version of Jenkins TestLink Plug-in while this book is being written is 3.0.2.
Jenkins TestLink Plug-in is licensed under the MIT License and its code is stored in github - http://github.com/
jenkinsci/testlink-plugin [http://github.com/jenkinsci/testlink-plugin].
4. TestLink Configuration
4.1 Installing TestLink
In this part of the tutorial we will show how to install and configure TestLink. Let's start by downloading
testlink-1.9.3.tar.gz from http://www.teamst.org. Decompress it with tar -zxvf testlink-1.9.3.tar.gz. Move the
directory created to your HTTP server root directory and open http://localhost/testlink-1.9.3 [http://localhost/
testlink-1.9.3] in your browser.
Now the installation wizard will guide you through the rest of the installation. But before going on, we need
to create a database in MySQL.
The next step is to create a user that TestLink will use to access the database.
If everything worked out correctly you should be asked to log in with user admin and password admin. The
examples in this tutorial require you to have a user with administrator rights in TestLink.
By default, the XML-RPC comes disabled in TestLink. Let's enable it by editing config.inc.php, located in
TestLink root folder.
$tlCfg->api->enabled = TRUE;
Finally, let's make sure that the attachments retrieved from the database are ordered by its ID. This way, the
order of attachments will be preserved in TestLink. We could use the date that the attachment was inserted in
database, however the precision of the date_added column is in seconds, what could lead to inconsistencies in
the way that attachments are displayed in TestLink.
Create a test project with name My first project, prefix MFP and make sure the following options are checked:
Enable Requirements feature, Enable Testing Priority, Enable Test Automation (API keys), Enable Inventory,
Active and Public. Click on Create button.
If the following screen is not displayed, review your previous steps or consult TestLink documentation for
further assistance.
Click on Define Custom Fields under the Test Project options box. Now create a custom field using the name
Java Class, label Java Class, available for Test Case, type string, enable on Test Spec Design and display on
test execution No. The plug-in retrieves the custom fields by its name and not by the value in its label.
The last step now is to assign this custom field to be used in our test project. Go back to the main screen and
click on Assign Custom Fields. It will take you to a screen with the list of the available custom fields. Select
the Java Class custom field and click on the Assign button.
Back to the main screen, in the top menu you will see the option Test Specification. Click on this option. The
test specification screen is quite simple. On the left you have the navigator, with the settings, filter and the tree
of test suites and test cases. Start clicking on your test project to see the test suite operations available.
Create a test suite with any name that you want. This field is not important for this tutorial. Once created, your
test suite will be displayed in the tree on the left. Now click on the test suite in the tree to see the available
test case operations.
Create a test case with any title or summary. The important information on this screen for the automation are the
execution type and the Java class (custom field created in the previous step). In execution type select Automated
and for Java class fill with the java class jenkins.plugins.testlink.examples.TestCurrentTime (present in the
example project).
In TestLink, you create a test plan outlining how you will test your application under test. Once you have a test
plan you can start to add test cases to your test plan, and then execute the test plan.
A build in TestLink can be seen as the execution of a test plan. Once the test plan is executed you are not
allowed to edit the test cases of this test plan (it wouldn't be right to change the scope or exit criteria of a test
case after it had already been executed).
Go back to the main screen and click on the Test Plan Management option available under the Test Plan box
on the right of the scren. Create a test plan with the name My first test plan, any description and make sure
that Active and Public are checked.
In the last box on the right of the screen, click on Add / Remove Test Cases and add the test case that you
created to your test plan.
Create a Build in TestLink is optional, as the plug-in automatically creates a new build if there is none with the
name that you provided in the Jenkins job configuration page. When you go back to your test plan, you should
see more options available in the Test Plan box and two other boxes: Test Execution and Test Plan contents,
as well as other options available in the top menu.
We are done with TestLink for now, the next step is to configure Jenkins.
5. Jenkins Configuration
5.1 Installing Jenkins
Download jenkins.war from http://www.jenkins-ci.org. Now open a terminal and execute java -jar
jenkins.war. This will initiate Jenkins in port 8080 by default (if you need to change that port, use --
httpPort=9999).
Jenkins creates a default workspace for you at ~/.jenkins or it uses the folder specified in JENKINS_HOME
environment variable.
Go to http://localhost:8080 to check if your installation is working. We will call this page as main screen from
now on. The examples in this tutorial require you to have administrator rights in Jenkins.
Just check the check box besides the plug-in name on the list and click on Install to install the plug-in. Jenkins
will download and install the plug-in automatically for you. Restart Jenkins to enable your plug-in.
After restarting Jenkins, go to Manage Jenkins again, this time click on Configure System option and look for
the TestLink section. Fill the TestLink configuration form with a name for your TestLink installation, the URL
of the XML-RPC API and your devKey.
By default the TestLink XML-RPC API URL is http://<host>:<port>/lib/api/xmlrpc.php. The devKey can be
obtained by entering TestLink, clicking on My Settings (top menu) and generating a new devKey, if there is
none yet. If you cannot see the API interface section in My Settings page, then it is very likely that you didn't
enable it yet. Go back to Chapter 4, TestLink Configuration to review your work.
Our job will use git to retrieve the test automation project. This is the project mentioned in Chapter 3,
Jenkins and TestLink Integration, and can be found at https://github.com/kinow/jenkins-testlink-plugin-
Click on Add build step button to expand its options and then click on Invoke TestLink. It will show a new
form with options to integrate your Jenkins job with TestLink. The plug-in configuration screen contains three
sections: TestLink Configuration, Test Execution and Result Seeking Strategy. to fill this form, we will use the
configuration created in TestLink throughout Chapter 4, TestLink Configuration.
TestLink Configuration
In this section, you are asked to provide the configuration that the plug-in will use to connect to TestLink and
retrieve the data for your automated tests.
TestLink Version Select the version that you created in the global
configuration
Test Execution
This section contains the configuration to execute your automated tests. You can add Single Build Steps, which
are executed once per build, or Iterative Build Steps, which are executed once per automated test found in
TestLink.
Single Build Steps Add an Invoke top-level Maven targets build step,
and as goals use test -DsuiteXmlFiles=suite.xml
Finally, here you can configure the Result Seeking Strategy. The plug-in implements the Strategy pattern for
seeking test results. What means that depending on your configuration, the plug-in might use certain algorithm
for parsing and updating test results in TestLink.
Each strategy can have different settings. You can use more than one strategy, but you will have to take care
to not have the same test in two different strategies.
Test Result Seeking Strategies Add the TestNG class name strategy.
TestLink Version
This is the name of your Test Project in TestLink. You can use environment variables in this field.
This is the name of your Test Plan in TestLink. You can use environment variables in this field.
Build Name
This is the name of your Build in TestLink. You can use environment variables in this field.
These Build Steps are executed only once in the job execution.
These Build Steps are executed iteratively for each test case retrieved from TestLink. For these Build Steps, a
set of environment variables are available. We will discuss more about them soon.
This is the Result Seeking Strategy chosen to seek and update test results in TestLink.
Include pattern
The plug-in uses this pattern to find test results of your tests execution (single test command or iterative). It
supports Ant-like expressions like TEST*.xml or target/**/testng*.xml.
Environment variables
The plug-in retrieves all the information from TestLink for your Test Project, Test Plan, Build and automated
Test Cases. You can then use any of this information to execute your tests. Jenkins itself provides the
Environment Variables, plus Build Environment Variables (such as BUILD_ID, which holds the date time of
your job).
The plug-in injects the information retrieved from TestLink as extra environment variables. This way you can
use the value of the Java class custom field value that you created in Chapter 4, TestLink Configuration in any
of your iterative Build Steps. Below you can find an example of how to execute a single test with Maven and
one of these environment variables.
As you can see, our test command uses the Java class custom field value to specify the name of the test to
Maven (Maven Surefire Plug-in, actually). Below you will find a list with the information that the plug-in
makes available for your job configuration. As custom fields names may vary, the strategy used is capitalize
the custom field name, replace spaces with _ and append it to TESTLINK_TESTCASE_, which represents
information of a Test Case in TestLink.
• TESTLINK_TESTCASE_ID
• TESTLINK_TESTCASE_NAME
• TESTLINK_TESTCASE_TESTPROJECTID
• TESTLINK_TESTCASE_AUTHOR
• TESTLINK_TESTCASE_SUMMARY
• TESTLINK_BUILD_NAME
• TESTLINK_TESTPLAN_NAME
• TESTLINK_TESTCASE_$CUSTOM_FIELD_NAME
Once your job execution is completed, refresh your current screen either by pressing F5 or by clicking over the
build name. The following screen must appear, showing a graph with the test results.
You can find more information on your tests by clicking on Test Results or on your build under Build History.
Everything seems to be right in Jenkins, let's go back to TestLink and click on Test execution option in the top
menu. It will bring a screen showing the result of your test execution.
You can see more information about the execution of your tests by clicking over it on the left tree. Notice
that by default the plug-in uploads the test result file. In this case, as we are using TestNG, it uploaded testng-
results.xml. It is useful as you can see what happened in your tests, e.g.: an exception stack trace.
Explore the reports available in TestLink to see the results of your tests by different perspectives.
Jenkins TestLink Plug-in supports three different formats of results: JUnit, TestNG and TAP.
7.1 JUnit
7.2 TestNG
<testng-results>
<reporter-output>
</reporter-output>
<suite name="Command line suite"
duration-ms="0"
started-at="2010-11-17T13:31:41Z"
finished-at="2010-11-17T13:31:41Z">
<groups>
</groups>
<test name="Command line test"
duration-ms="0"
started-at="2010-11-17T13:31:41Z"
finished-at="2010-11-17T13:31:41Z">
<class name="br.eti.kinoshita.Test">
<test-method status="FAIL"
signature="testVoid()"
name="testVoid"
duration-ms="0"
started-at="2010-11-17T13:31:41Z"
finished-at="2010-11-17T13:31:41Z">
</test-method>
</class>
</test>
</suite>
</testng-results>
1..3
ok 1 testOk
ok 2
not ok 3
There are three clear advantages in using this approach. First, if you are already using Jenkins as continuous
integration server and TestLink as test management tool, then you won't have another tool to worry about.
Simply install the plug-in and then DevOps will keep working in Jenkins, testers will keep working in TestLink
and your boss will be more than happy to know that he won't need to buy another tool and training for an
automated tests management tool.
Secondly, it is language independent. You can run tests in PHP, Perl, Python, Java, Lua and even in C or C++.
The only limitation here is that you have to output your test results either in JUnit, TestNG or TAP.
And lastly, it is free. The plug-in team members are contributors of TestLink and maintainers of the TestLink
Java API. We try to fix the issues in Jenkins' JIRA [http://issues.jenkins-ci.org] as fast as they can. So if you
use the plug-in, send us your feedback, write in the plug-in Wiki about your case or buy us a beer.
9. Appendix
9.1 Adding attachments to your test results
Each test result file is automagically attached to its automated test case in TestLink. That is the default behavior
in the plug-in. You can extend it, only if you are using TAP. You will have to create a YAMLish following the
example below (it is important that you encode the file content in Base64).
1..2
ok 1
not ok 2 - br.eti.kinoshita.selenium.TestListVeterinarians#testGoogle
---
extensions:
Files:
/tmp/screenshot3562328890173159732.png:
File-Location: /tmp/screenshot3562328890173159732.png
File-Title: screenshot3562328890173159732.png
File-Description: Main page
File-Size: 114542
File-Name: screenshot3562328890173159732.png
File-Content: "iVBORw0KGgoAAAANSUhEUgAAA+IAAAJqCAYAAACvjvpKAAAgAElEQVR4nOy9d1RU5/r3ff543+dZ\r\
\n613v8zy/95RfjjkmFmwgVXrvvffee1PBjtKbCoJ0qaIodqMYe8EWwRo1atQkRmOixkTFAkYFvu8f\r\
...
...
File-Type: image/png
An issue that wasn't solved yet is that if you are running your job in a distributed environment, then the plug-
in won't be able to find the attachments for your test result.
As well as attachments, the only way to use Platforms while integrating Jenkins and TestLink is using TAP.
You have to create a YAMLish entry like the following.
1..3
ok 1
ok 2
---
extensions:
TestLink:
Platform: EC1
...
ok 3
As you can see above, the TAP Stream has the platform EC1. The plug-in scans a TAP Stream looking for this
entry structure in each test result and in the test plan.
Click on the help icon on the right to see which options you can enable. They are used by testlink-java-api
[http://testlinkjavaapi.sf.net] to set properties in the connection.
Among the properties, you may have to set xmlrpc.basicUsername and xmlrpc.basicPassword with the
credentials used for basic authentication.
For SSL, there are guides available in the Internet showing how to add a certificate to the Java key store and
proceed with a SSL connection.
Bibliography
[JenkinsTestLink] Jenkins TestLink Plug-in [http://wiki.jenkins-ci.org/display/JENKINS/TestLink+Plugin].
Copyright © 2011 The Jenkins TestLink Plug-in team.
[TAP] Test Anything Protocol Website [http://testanything.org/]. Copyright © 2011 Test Anything Protocol
Community.