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 tutorial will explore the synergy between Testkube and Azure Pipelines, illustrating how this integration enhances continuous testing practices.
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:
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 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 tutorial.
At a high level, this is what we are going to do. The code for this tutorial 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.
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.
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.
```js
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);
}
```
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.
```yaml
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
```
Pro Tip: You can also use this sample workflow generated by Testkube to create and configure your Azure Pipeline.
The above workflow does the following things:
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.
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.
At this point, our Azure Pipeline is configured to be triggered on every new PR on the main branch of the GitHub repository.
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.
You see two jobs here, that is because we already have a GitHub action enabled in this repository from our previous tutorial.
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.
If the test passes, our pipeline will update the status in the PR, and a user can merge the PR.
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.
In this tutorial 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!
Testkube is a test execution and orchestration framework for Kubernetes that works with any CI/CD system and testing tool you need, empowering teams to deliver on the promise of agile, efficient, and comprehensive testing programs by leveraging all the capabilities of K8s to eliminate CI/CD bottlenecks, perfecting your testing workflow. Get started with Testkube's free trial today!
Related topics: