logo logo

Integration Testing in Jenkins X

TestProject Integration Testing in Jenkins X

In this step by step tutorial we are going to build a CI/CD solution for a modern cloud application based on microservices with Jenkins X. By the end of this tutorial, we will have a working CI/CD solution that will enable us to develop, test and deliver our application in a fast and reliable way.

Tutorial Chapters

  1. Continuous Deployment with Kubernetes and Jenkins X (Overview)
  2. Jenkins X Serveless Architecture (Chapter 1)
  3. Install & Setup Jenkins X Serverless (Chapter 2)
  4. Import Existing Project into Jenkins X (Chapter 3)
  5. Create Custom Build Pack for Jenkins X (Chapter 4)
  6. You’re here → Integration Testing in Jenkins X (Chapter 5)

In this chapter, we will learn how to implement integration testing for the services that we deploy with Jenkins X.

In order to understand where to implement the integration tests, you need to understand their purpose – To verify that all the services in our production environment will communicate with each other in the correct way.

In Jenkins X you can have as many environments as you want, but now we will focus on the staging environment since this environment simulates the next version that is going to be released to the production environment. Hence, if the services communicate in the correct way in the staging environment, then we can assume that if they will be transferred to the production environment they will work seamlessly.

If you’ve followed the tutorial from the start, you should have a staging environment that includes: Two working services, Backend1 and Backend2. These services have no interaction with each other so there is no actual integration testing we can perform to verify that the services are communicating correctly.

To make the integration testing example meaningful, we will add a frontend service that interacts with both of the backend services.

For the purpose of the tutorial, if you have already forked and cloned the main tutorial repository, then skip the next step and simply enter the Frontend folder inside the repository folder.

If you have not already cloned the main tutorial repository, then run the following commands:

git clone https://github.com/$GIT_USER/$PROJECT_NAME
cd $PROJECT_NAME/frontend
jx import --batch-mode

When the import is successfully finished, verify that the 3 services are up and running in your staging environment.

To verify that the 3 services are available, you can run the following command:

jx get applications

How to Execute Integration Tests with TestProject via API

TestProject is a community powered test automation platform that is completely free. It is built on top of Selenium and Appium, supports all major operating systems, and enables every member of your software team to collaborate and test Web, Android and iOS apps, effortlessly. TestProject is the perfect fit for integration testing within a CI/CD pipeline, since TestProject exposes a RESTful API which allows R&D teams to schedule and trigger automation, get status and retrieve testing results. In addition, TestProject Agents can be deployed with ease on various platforms (both local and remote), including a dockerized version of the Agent that can be deployed serverless, which allows for parallel distributed testing on-demand. 

Let’s get started!

  1. Create a TestProject account here, it’s completely FREE!
  2. Download and register the TestProject Agent.
  3. Create your integration tests. In this example we will use recorded tests, but you can also use TestProject to develop Selenium and Appium coded tests in C# or Java as well.
  4. Generate your API key with TestProject to access TestProject Platform from your CI/CD tools.
  5. Execute a test automation job in TestProject using their API.
  6. For example, you can use the following Python script to execute your TestProject job from your CI/CD tool: https://github.com/testproject-io/jenkinsx-tutorial/blob/master/trigger-job.py

Now let’s implement our integration tests! The first thing you need to do is to clone the staging environment repository to your development environment. Use the following commands:

git clone https://github.com/$GIT_USER/environment-$CLUSTER_NAME-staging
cd environment-$CLUSTER_NAME-staging

After cloning the reposiroty to your development environment, inside the home directory folder we can find a file called jenkins-x.yaml. This file describes the steps that represent the pipeline for the deployment of services to the staging environment.

In order to execute the integration tests after the build, we need to add the following commands to this file:

      - sh: echo “Executing integration tests!”
      - sh: python trigger-job.py

The new file should look like this: https://github.com/testproject-io/jenkinsx-tutorial/blob/master/staging-pipeline.yml

Now that we’ve added the commands that will execute the integration tests, we can push the changes to Git.

Congratulations, the integration tests will be executed every time anything is deployed to the staging environment! 🎉

You can verify this by looking at the build logs:

jx get build logs $GIT_USER/environment-$CLUSTER_NAME-staging/master

Happy jx’ing and good luck! 😉👌


Alexander Nikitin

About the author

Alexander Nikitin

Experienced DevOps engineer with vast knowledge in automation and network systems. Working as a DevOps Engineer at TestProject.

Leave a Reply