Interested in Solving your Challenges with XenonStack Team

Get Started

Get Started with your requirements and primary focus, that will help us to make your solution

Proceed Next

Serverless

Automated Testing Pipeline with GitLab CI | Overview

Navdeep Singh Gill | 14 August 2024

XenonStack Feature Image

What is a Testing Pipeline?

An Automated Testing Pipeline is a group of jobs or tasks that are executed in stages also called batches. Pipelines comprise -
  • Jobs that define what to run. For example, the compilation of code or test runs.
  • Stages are defining when and how to run. For example, that test run after compilation of code.
  • Jobs in a stage are executed in sequential/parallel by Runners if there are enough concurrent Runners.
If the jobs in a stage -
  • Succeeded, then the pipeline moves to the next step.
  • Fails, the next stage will not get executed.
A software practice that can be automated with the combination of different tools related to testing.. Click to explore about, Application Automated Testing

Stages in Automated Testing Pipeline

As an example, imagine a pipeline consisting of four stages, administered in the following order -
  • Build A job called compile.
  • Test - Two jobs called test and test2.
  • Staging - A job called deploy-to-stage.
  • Production - A job called deploy-to-prod.
Delivery pipeline shall meet the following requirements -
  • source code in Gitlab
  • there is an automated mechanism triggered by a code change that
  • builds an app package
  • deploys an app on local or in the cloud (e.g., Heroku)
  • runs automated tests and offer a run report

What is the process of building Testing Pipeline?

The steps for building testing pipeline are listed below:

Write the script and run locally

First of all, we will write test scripts to let our first manual test run automatically. Selenium is a well - known web automation tool. With the idea of a basic test model, we can quickly identify the three major components in the script -
  • Set up
  • Run test case
  • Tear down
We can run various test_cases with setUp before the test and tearDown after the test.
ML pipeline is constructed to allow the flow of data from raw data format to some valuable information. Click to explore about, Machine Learning Pipeline Deployment

Setting up a runner with your testing environment

Gitlab runner can be installed in three ways to set up a runner with your testing environment.
  • Use a Docker
  • Download a binary
  • Use a repository for rpm/deb packages.

Set up an image with the testing environment

Build an image with the testing environment Test running requires a clean environment. To create a clean environment, we don't want to establish up a real machine each time and wait for hours to install all the necessary software. The concept of the container helps. Docker helps you build an image of your testing environment. The image includes all the software that needs to be pre-installed and run like a virtual machine on that container. You can create a new container with Docker and pull the same image every time, whenever you want to start over from your default environment. Forex - We want our image to pre-install the following to perform our test with the Selenium Python client -
  • Python
  • Google Chrome
  • Chrome driver
Create a Dockerfile, build the image and upload it to our Docker Cloud. Then you have an environment ready for performing the UI tests.

Setting Up GitLab CI for Automated Testing Pipeline

Create a job template for your product When commit/new codes are pushed to the repo, will look for directory and triggers and build according to the configured settings. GitLab Runner uses this file to manage the 'project's jobs which define how the project should be built.
image: joyzoursky/python-chromedriver:3.6
before_script:
  - pip install -r requirements.txt
stages:
  - test
  - report
test_suite_1:
  stage: test
  script:
    - python -u test_suite_1.py
test_suite_2:
  stage: test
  script:
    - python -u test_suite_2.py
send_report:
  stage: report
  script:
    - python send_report.py
GitLab looks for job template and then installs the required packages and then starts the process. It pulls the environment image in the first line from joyzoursky / python - chromedriver:3.6-xvfb in this script. Then it installs the required packages, sets the required variables, and then it starts the process. In this example, there are two stages of the build process: test and report. The jobs at that stage will be run simultaneously at each stage. In the same step, you can define criteria if they can move in sync.

Run and report periodically

Pipelines can be set up according to the user requirements. Tests can be made run on every build triggered on the pipeline or can be run periodically by setting up Cron Jobs and scheduling the time by cron syntax. Two different ways to integrate this into our system -
  • Running the tests every time a new code gets pushed to the project.
  • Running the tests periodically.

The nightly run requirement depends on the team where they want to run all the tests (smoke & regressions) when there is no deployment. Test runs at night will yield useful test reports. Executing the tests on each change of code as part of the CD pipeline. The reason for this is that E2E tests are slow to run. We do not want these tests to slow down our pipeline as it will delay our process and cycle and will affect pull requests, merges, and deployments to different environments. We wanted a set of core End to End tests we can run regularly that let us know if anything is broken or off. So we can run these tests on a nightly basis via a Jenkins cron job.

Reporting Test results can also vary based on the teams, depending on their requirements such as intimating on the slack channel, generating HTML reports, saving test runs in DB and displaying them on dashboards. We can use Slack real-time messaging API to do the reporting so that we can receive notifications in the corresponding project channels.

  • Slack Notification
  • HTML Reporting
  • Dashboard Reporting
GitLab is one application for the entire lifecycle of DevOps
  • Build your application using the GitLab Runners
  • Run unit tests and integration tests to check that your code is valid
  • Look at the live preview of your development branch with Review Apps before merging it into stable
  • Deploy to the multiple environments like staging and production, and support advanced features like canary deployments
  • Monitor the performance and status of your application

Software testing is an important process that ensures customer satisfaction in the application. Click to explore about, AI in Software Testing

Automated Testing Pipeline Approach

Setting up an Automated Testing Pipeline makes QA life easier by finding the bugs in the application. Now, whenever code is updated on the production branch or code change in the project, this automated test is triggered and tests are done automatically and generate test reports to notify Developers and QA. Failure results will be pushed back to Slack channel to notify the developers. This makes the automated testing process becomes more manageable.To Adapt Automated Testing as a testing practice we recommend taking the following steps -

Table of Contents

navdeep-singh-gill

Navdeep Singh Gill

Global CEO and Founder of XenonStack

Navdeep Singh Gill is serving as Chief Executive Officer and Product Architect at XenonStack. He holds expertise in building SaaS Platform for Decentralised Big Data management and Governance, AI Marketplace for Operationalising and Scaling. His incredible experience in AI Technologies and Big Data Engineering thrills him to write about different use cases and its approach to solutions.

Related Articles

5G Network Concerns And Strategies In India

5G Network Concerns And Strategies In India

5G is the fifth generation of cellular networks. Up to 100 times faster than 4G, 5G is creating never before seen opportunities for people and ...

14 August 2024

How 5G is Transforming Healthcare Industry?

How 5G is Transforming Healthcare Industry?

5G networks helps healthcare providers deliver more personalized and precise care by enabling real time data analysis and remote monitoring of ...

12 August 2024

Serverless Computing on AWS | Comprehensive Guide

Serverless Computing on AWS | Comprehensive Guide

A Comprehensive Guide for Serverless Computing on AWS with Amazon Services - Lambda and Steps for building Applications on AWS

14 August 2024