Introduction
Continuous Integration and Continuous Deployment (CI/CD) pipelines are critical for accelerating software delivery while ensuring code quality. When paired with automation testing, they help catch bugs early, reduce manual effort, and streamline the release process. In this article, we’ll explore how to integrate automation testing into CI/CD using GitHub Actions, one of the most popular CI/CD tools.
What is CI/CD?
- CI (Continuous Integration): Developers frequently merge code into a shared repository. Automated builds and tests run to validate each change.
- CD (Continuous Deployment/Delivery): After passing tests, the code is automatically deployed to staging or production.
Why Integrate Automation Testing into CI/CD?
- Ensures consistent testing on every commit or pull request.
- Detects regressions and bugs early in the pipeline.
- Reduces manual QA cycles.
- Improves team confidence in frequent releases.
Using GitHub Actions for Automation Testing
Sample Test Code
1. These bring in external libraries required for the test
Purpose: Allows access to WebDriver for browser automation and TestNG for annotations
![Github actions]()
2. Class Definition
Purpose: Acts as a container for the test logic. The driver is declared at the class level so it can be accessed in all methods.
![Class definitation]()
3. Setup Method (@BeforeMethod): Runs before each test to initialize the browser.
Purpose: Launches the browser and navigates to the login page before each test.
![Setup method]()
4. Test Method (@Test): The actual test that validates login functionality.
Purpose: Performs the test in this case, checking if the title after login is as expected.
![Test method]()
5. Teardown Method (@AfterMethod): Runs after each test to close the browser.
Purpose: Ensures that the browser is closed after the test completes to avoid resource leaks.
![Teardown method]()
GitHub Actions Workflow
1. Workflow Name
This is the name that will appear in the GitHub Actions UI, and it helps identify what the workflow does (e.g., "Run UI Tests")
![Workflow name]()
2. Trigger Conditions
Specifies when the workflow should run.
In this case
- On a push to the main branch
- On a pull request targeting the main branch
![Trigger condition]()
3. Job Definition
A job named test is defined, and runs on specifies the operating system (Ubuntu) for the virtual machine.
![Jobs]()
4. Services Section (Optional)
- If you're running Selenium or browser-based tests, you may need an additional service like Chrome in a container.
- xvfb here refers to a headless display environment using a Selenium Chrome container.
![Services]()
5. Checkout Repository
Download your project source code to the runner so it can be built and tested.
![Checkout repository]()
6. Set Up Java
- Installs Java 17 using the Temurin (Eclipse Adoptium) distribution.
- Required for building and running Java-based test frameworks.
![Set up java]()
7. Cache Maven Dependencies
- Speeds up builds by caching Maven dependencies.
- Avoids redownloading libraries on every run.
![Cache Maven Dependencies]()
8. Run Automated Tests
- Executes the test cases using the Maven command.
- clean test cleans the previous build and runs all tests defined in the project.
![Run Automated Tests]()
Best Practices
- Run fast tests early
- Use environment variables to handle test configs
- Parallelize tests for speed
- Trigger tests on pull requests, not just on merges
- Integrate test reports
Conclusion
The addition of automation tests to CI/CD pipelines fosters better quality software, reduces bugs, and builds a DevOps culture. GitHub Actions provides a highly configurable and development-friendly environment to create those pipelines. The principal guidelines are the same regardless of the technology used, be it Java, Python, or JavaScript: automate early, test often, and deploy with confidence.