How to Setup TeamCity for Load Testing

Testing in general is an indispensable part of the continuous delivery process and load testing should not be an exception. Let’s take a look at how to set it up in TeamCity.

TeamCity is a continuous integration and build server from JetBrains. Although it is capable of running JMeter load tests out of the box, you still must analyze the results manually. That’s not very useful as the concept of CI is based on automation. That’s where SmartMeter.io comes in. Let's dive in.

1: Installation

You need to download and install SmartMeter.io to be able to run the load tests.

Let’s assume you have TeamCity already functional and your TeamCity user has proper permissions to run the SmartMeter.io installation.

2: Basic information

Before we begin, you have to gather some information about your SmartMeter instalation:

  • SmartMeter.io instalation directory - TeamCity’s agent need to have access to this directory and to run SmartMeter.sh in it. Example: /usr/local/bin/smartmeter/

  • Test directory - directory, that contains prepared .jmx scripts. This is usually pulled from Version Controll System (VCS). Example: /home/teamcity/tests.

  • Reports directory - directory to store repors from SmartMeter.io. Theese reports will be artifacts for your build runs. Example: /home/teamcity/reports in our setup.

3: Running SmartMeter.io tests from TeamCity

3.1: Configuring Build Parameters

1) Add new parameters to your build configuration. Go to Parameters section of your build configuration. Click button Add new parameter.

team-city-ci-load-performance-1

2) Add ReportIndex to parameters. Create parameter with this configuration

  • Name - ReportIndex

  • Kind - Configuration parameter

  • Value - index.html

  • Spec - text validationMode='not_empty' label='Perf Report' display='normal'

team-city-ci-load-performance-2

3) Add TrendsIndex to parameters. Almost the same as in the previous step.

  • Name - TrendsIndex

  • Kind - Configuration parameter

  • Value - trends.html

  • Spec - text validationMode='not_empty' label='Trends' display='normal'

team-city-ci-load-performance-3

4) Add ReportUrl to parameters. This will be the URL where you find report of the build. We will use here predefined build parameters: teamcity.serverUrl, system.teamcity.buildType.id, build.number

  • Name - Reporturl

  • Kind - Configuration parameter

  • Value - http://%teamcity.serverUrl%/repository/download/%system.teamcity.buildType.id%/%build.number%/

  • Spec - text validationMode='not_empty' label='Report Url' display='normal'

team-city-ci-load-performance-4

5) Now we have these 3 parameters configured.

team-city-ci-load-performance-5

3.2: Configuring artifacts

1) Go back to General settings of Build configuration settings of your project.

team-city-ci-load-performance-6

2) Add parameters to Artifacts paths.

%ReportIndex%
%Reporturl%
%TrendsIndex%
/home/teamcity/reports/report-%build.number%

team-city-ci-load-performance-7

3.3: Configuring build steps

1) Go to build configuration of your project and add new build step. Set up:

  • Runner type: Command Line

  • Step name: Run Smartmeter test (or whatever you like)

  • Run: Executable with parameters

  • Command executable: path to SmartMeter /usr/local/bin/smartmeter/SmartMeter.sh

Command parameters: runTestNonGui <path/to/tests/dir>/test.jmx -Jetn_report_name=%build.counter% -Jetn_reports_path=<path/to/reports/dir>
where <path/to/tests/dir> is directory where you store or download your test scripts and <path/to/reports/dir> is directory where you want to store reports

team-city-ci-load-performance-8

2) Next we want to create report page. Add second build step with this config:

  • Runner type: Command Line

  • Step name: Create report page (or whatever you like)

  • Run: Custom script

Custom script:

echo '<script>location="%Reporturl%%ReportIndex%"</script>' > %ReportIndex%

team-city-ci-load-performance-9

3) And final build step is for creating trends page

  • Runner type: Command Line

  • Step name: Create trends page (or whatever you like)

  • Run: Custom script

Custom script:

echo '<script>location="%Reporturl%%TrendsIndex%"</script>' > %TrendsIndex%

team-city-ci-load-performance-10

3.4: Configuring report tabs

We have set up parameters and configured build steps. Now we want to set up reports to appear right in the build view or project view.

1) Go to your TeamCity project settings.

team-city-ci-load-performance-11

2) Open Report tabs section. You will see Create new project report tab button and Create new build report tab button.

team-city-ci-load-performance-12

3) By using these buttons we will add reports to our project or build view. Let’s start with build report. Click on Create new build report tab button. Configuring it is very easy. Just type the name of the tab to Tab Title, e.g. “Perf test report”. Leave Start page unchanged - it shloud contain value “index.html”.

team-city-ci-load-performance-13

4) Now click Create new project report tab button and set these values

  • Tab Title: Perf trends

  • Get artifacts from: choose name of your project’s build configuration. In second combobox choose Last successful build

  • Start page:  trends.html

team-city-ci-load-performance-14

5) You should see tabs in configuration.

team-city-ci-load-performance-15

3.5 - First try run

If everything is configured, you can try first run of a test.

1) Go to your project home and click Run button.

2) After few moments SmartMeter test will start. You can see progress in build log

team-city-ci-load-performance-16

3) After finishing the test, SmartMeter will generate report and TeamCity will add it to Report Tabs. You can see Result analysis in Build detail.

team-city-ci-load-performance-17

4) Trends analysis can be seen in Project home view in tab Perf trends. Run your test multiple times, and you will see how tables and charts will change.

team-city-ci-load-performance-18

4: Next steps

You should now be able to run load test in TeamCity with SmartMeter.io. If you’re not familiar with the tool and want to learn more about test creation and other features visit the learn sectionYou can also follow tutorial for Jenkins and Bamboo.