DEV Community

Cover image for Integrating Testkube With Azure Pipelines For Continuous Testing
michael20003 for Kubeshop

Posted on

Integrating Testkube With Azure Pipelines For Continuous Testing

In the fast-paced world of software development, agility is key. Teams strive to expedite feature releases, yet the critical process of testing often lags behind. To truly achieve agility and ensure reliability, automated testing must be woven throughout the development lifecycle.

Enter the concept of Continuous Testing, or TestOps, which embodies the integration of testing into DevOps practices. This isn't just about triggering tests upon code commits or automating report generation; it's about embedding a robust testing framework within your CI/CD ecosystem.

Testkube emerges as a solution specifically designed to facilitate testing in Kubernetes environments and to dovetail with CI/CD workflows effortlessly. This blog post will explore the synergy between Testkube and Azure Pipelines, illustrating how this integration enhances continuous testing practices.

Leveraging Testkube with Azure Pipelines for Enhanced TestOps

Azure Pipelines, a pivotal component of Microsoft Azure's DevOps services, offers seamless integration with leading version control systems like GitHub and GitLab. It utilizes an azure-pipelines.yaml file to manage pipeline triggers and job configurations, enabling automated builds and deployments with ease.

Testkube, on the other hand, is a versatile testing framework designed to harmonize with various CI/CD tools, bringing your preferred testing mechanisms into the Kubernetes ecosystem. By treating tests as Kubernetes resources through Custom Resource Definitions (CRDs), Testkube revolutionizes test management by allowing tests to be handled as code.

Integrating Testkube with Azure Pipelines unlocks significant advantages:

  • Enhanced TestOps: This integration erases the traditional boundaries between testing and development, fostering a culture of continuous testing. It ensures product reliability by facilitating testing at every stage of the development process, accommodating rapid scaling and deployment speeds.

  • Seamless Continuous Testing: With Testkube and Azure Pipelines, testing becomes a continuous process that automatically triggers with every code commit. This ensures comprehensive testing with each change, embedding quality directly into the CI/CD pipeline.

  • In-depth Insights: Testkube excels in capturing and analyzing data from your executed tests. It leverages this information to generate detailed insights and dashboards, offering a clear view of test performance and trends over time.

This integration not only streamlines workflows but also empowers teams to maintain high-quality standards, ensuring agile, reliable product development with Testkube and Azure Pipelines.

Integrating Azure Pipelines With TestKube

Integrating Testkube with Azure Pipelines follows a process similar to what we did for GitLab and CircleCI in the previous posts. In this case, we'll configure Azure Pipelines with the GitHub Repo used in an earlier blog post.

  • Create a DevOps organization in Azure and then create a new project to get started.
  • On the first run, it will ask you to configure your code repo with Azure Pipeline.
  • Create an azure-pipelines.yml in the root of your GitHub repository.
  • The pipeline will create and execute a k6 test on a cluster with Testkube configured.
  • Lastly, we'll configure a branch protection rule that will not allow a change to be merged if the test fails.

At a high level, this is what we are going to do. The code for this blog post is available in this GitHub repo. It has a folder named k6, which has the test, and an azure-pipelines.yaml file with the Azure Pipeline configuration.

Pre-requisites

Once the prerequisites are in place, you should have a target Kubernetes cluster ready with a Testkube agent configured. You should also have a GitHub repository configured with Azure Pipelines integrated with Testkube.

Note: Refer to our API Token document to create the API token. To find the Org ID and environment IDs, log in to your Teskube Cloud dashboard, head to any existing tests page, navigate to CI/CD integration, and choose GitHub. Copy the environment and organization IDs from here.

You'll also need to create variables in Azure Pipelines to store these IDs and the token.

K6 Test

We will create a k6 test that performs a load test on the testkube.io website and checks if the response time is less than 1000 milliseconds. If the response is more than that, the test will fail.

import http from 'k6/http';
import { check, sleep } from 'k6';

export let options = {
  vus: 1,            // Virtual Users
  duration: '10s',   // Duration of the test
};

export default function () {
  // Send an HTTP GET request to the website
  let response = http.get('https://testkube.io');   // Replace with your URL

  // Check if the response time is less than 1000 milliseconds
  check(response, {
    'Response time is less than 1000 milliseconds': (r) => r.timings.duration < 1000,   // Check if response time is less than 1000 milliseconds
  });

  // Add a sleep period (in this case, 1 second) between requests
  sleep(1);
}
Enter fullscreen mode Exit fullscreen mode

Configuring Azure Pipeline

We configure the Azure Pipeline to execute whenever a new pull request is made. The job uses the Testkube API key, ORG_ID, and ENV_ID, saved as Azure Pipeline variables.

trigger:
  - main

pool:
  vmImage: 'ubuntu-latest'

stages:
  - stage: Test
    jobs:
      - job: RunTestkube
        steps:
          - task: SetupTestkube@1
            inputs:
              organization: '$(TK_ORG_ID)'
              environment: '$(TK_ENV_ID)'
              token: '$(TK_API_TOKEN)'
          - script: |
              git clone https://github.com/techmaharaj/testkube-GH.git
              cd testkube-GH/k6
              testkube create test --name k6-test --type k6/script --update -f testkube.js
              testkube run test k6-test
            displayName: Run Testkube Test
Enter fullscreen mode Exit fullscreen mode

Pro Tip: You can also use this sample workflow generated by Testkube to create and configure your Azure Pipeline.

Image description

The above workflow does the following things:

  • Configures a job to connect with Testkube cloud using the Testkube token, organization, and environment ID.
  • Creates and executes the k6 test using kubeshop/testkube-cli on the AKS cluster.
  • Based on the result, the status will be updated in the pull request. If the test passes, the merge option will be enabled, and anyone can merge it. However, if the test fails, the merge will not be available - we'll configure a branch protection rule to prevent the PR from being merged if the run fails.

Configuring GitHub Repo

You first need to create an Azure DevOps organization. Once this is made, you'll be prompted to add your first project. In this case, we're using a GitHub project. So, we can choose GitHub and follow the prompts to connect your GitHub repository to Azure DevOps.

Image description

After successfully creating the project, you need to make your pipeline. Azure will provide you with a default pipeline code that you can commit to your repo. However, since we already have our configuration, we will use that.

Image description

At this point, our Azure Pipeline is configured to be triggered on every new PR on the main branch of the GitHub repository.

Trigger Testkube Test

To check if everything works correctly, raise a new pull request in the repository with some changes. You'll see that your action is triggered almost immediately.

Image description

You see two jobs here, that is because we already have a GitHub action enabled in this repository from our previous blog post.

At the same time, you can also see the execution on Azure Pipeline. In the background, our test will run on the target Kubernetes cluster specified.

Image description

Image description

If the test passes, our pipeline will update the status in the PR, and a user can merge the PR.

Image description

However, if the workflow fails, the CI job will update the workflow status as failed in the PR. Merging will be blocked because of the branch protection rule that we have created, which prevents merging if the test fails.

Conclusion: Revolutionizing Testing with Testkube and Azure Pipelines

In this blogpost, we learned about the pivotal role of continuous testing in modern software development, spotlighting how it significantly uplifts testing practices. We delved into the synergy between Testkube and Azure Pipelines, demonstrating a seamless integration that facilitates an efficient CI/CD workflow. By integrating a k6 test with Testkube and executing it through Azure Pipelines, we showcased a practical workflow that enhances testing efficiency and reliability.

For a deeper dive and more comprehensive guidance on harnessing Testkube within your CI/CD ecosystem, our documentation offers extensive insights. Embrace TestOps by experimenting with Testkube and witness firsthand the transformation it brings to your testing strategy.

Should you have any queries, need guidance, or wish to share feedback, our Slack Community is a vibrant space for support and knowledge exchange. Embark on your journey towards more proactive, streamlined testing today.

Happy testing!

Top comments (0)