Skip to content
Go back

Test Automation - Pre-Merge Testing with GitHub Actions: A Step-by-Step Guide

Published:

Introduction

In this article, I will explain how to build a Pre-Merge Testing pipeline using GitHub actions.

The project was developed together withElias Shourosh.

link to the project.

The technological stack used to implement the solution is:

Programing language:Python

Testing Framework:pytest

Reporting Framework:Allure

What is GitHub Actions?

according tothis article:

GitHub Actions is an API for cause and effect on GitHub: orchestrate any workflow, based on any event, while GitHub manages the execution, provides rich feedback, and secures every step along the way. With GitHub Actions, workflows and steps are just code in a repository, so you can create, share, reuse, and fork your software development practices.

GitHub actions are free and support public repositories. The article will be demonstrated using my public repository, which contains a suite of E2E tests written in Python.

The Importance of Pre-Merge Testing

While code reviews play a vital role in catching errors, they may not be enough to guarantee overall code quality and consistency. Pre-merge testing, coupled with code reviews, is a critical step to ensure that every change to the main codebase undergoes thorough testing, preventing regressions and maintaining a high standard of code quality. Additionally, keeping the codebase consistent and adhering to coding standards can be challenging without automated tools. Manual formatting and sorting of imports become tedious as the codebase grows, leading to inconsistencies and reduced readability.

Implementing the Solution

We need to create a .github folder at the root of our project, and inside it create a workflow folder. Inside it, we create our workflows which are YAML files.

No alt text provided for this image

The workflow can be found here

Walkthrough

We are running the workflow on every push or PR to the main branch.

No alt text provided for this image

It runs the build on an Ubuntu instance provided by GitHub, here is thespecification for GitHub-hosted runners. Of course, there is also an option of creating custom runners. this workflow is pretty simple so I used a hosted runner.

No alt text provided for this image

now a series of workflow steps are executed in order:

No alt text provided for this image

No alt text provided for this image

No alt text provided for this image

No alt text provided for this image

No alt text provided for this image

No alt text provided for this image

in our case, it’s a simple test that just opens the base URL and ensures we actually got there:

No alt text provided for this image

this test could be far more complicated, but this one serves the purpose of our project.

the rest of the pipeline uploaded allure results to GitHub Pages.

Now with this pipeline, we can see that code is checked for formatting and imports ordering automatically, the workflow will not continue if these steps will fail.

No alt text provided for this image

our pre-merge test is also passing:

No alt text provided for this image

Now that the pre-merge testing has been successfully completed, validating the code changes for quality and consistency, we can confidently proceed with the code review process. The automated pre-merge testing using GitHub Actions has ensured that potential regressions and critical errors are identified and addressed beforehand, providing a solid foundation for the code review.

No alt text provided for this image

In conclusion

In this article, we reviewed the creation of a Pre-Merge Testing pipeline using GitHub actions python, and pytest.

Further reading on GitHub action features can be found in this link.

Happy testing!


Suggest Changes

Have a challenge? Let's Talk


Previous Post
Test Automation - How To Edit Cookies in Selenium Python
Next Post
Test Automation - How To Use Custom User Agent In Selenium Python Or Playwright Python To Avoid Security Bots