Quick test reports using Allure + TestNG + GitHub Actions

Luiz Gustavo De O. Costa
5 min readAug 18, 2022

Every system should be testable. Starting from this premise why not combine Allure + TestNG + GitHub Actions to present the test history?

In this article, I’ll show an easy and quick way to have it in your system.

1. Definitions

  • Allure Report — A flexible lightweight multi-language test report tool designed to create fancy and clear testing reports and loved by the community, maintained by the Qameta Software team.
  • TestNG — TestNG is a testing framework inspired by JUnit and NUnit but introduces some new functionalities that make it more powerful and easier to use
  • GitHub Actions — GitHub Actions makes it easy to automate all your software workflows, now with world-class CI/CD. Build, test, and deploy your code right from GitHub. Make code reviews, branch management, and issue triaging work as you want.
  • Git Fork — The Forking Workflow is fundamentally different than other popular Git workflows. Instead of using a single server-side repository to act as the “central” codebase, it gives every developer their own server-side repository. This means that each contributor has not one, but two Git repositories: a private local one and a public server-side one. The Forking Workflow is most often seen in public open source projects.[Atlassian]

2. Tech stack

  • Java 11
  • IntelliJ Ultimate or other IDEA
  • GitHub account

3. How does Allure work?

The diagram below shows how Allure works, for more click here.

Allure diagram
Allure report

4.Hands-on

4.1.Fork

Go to GitHub and create a fork of the repository https://github.com/allure-examples/allure-testng-example.

GitHub page — Steps to create a fork
GitHub — Fork in action

Once the fork is created, the repo will be available in your repo.

GitHub — Forked repository

4.2. GH (GitHub) pages

In order to have the test report in your branch, this step is required. Confirm if the branch is gh-pages, because this reference will be used on GitHub Actions.

How to check it?

  1. Go to Settings
  2. Pages
  3. And confirm if the option gh-pages is selected.
GitHub — GitHub Pages

4.3. Project

I’m using the IntelliJ Ultimate edition in this article, but as I said before, you can use any IDEA.

IntelliJ — Project explorer

4.4. Project configuration

After completing the steps, your project has the structure below, otherwise, you can clone this project https://github.com/luizgustavocosta/allure-testng-example.

IntelliJ — Project explorer

4.5. GitHub Action

This will be triggered for any new code on the branch, ie, for any push, the pipeline will be executed.

To tell to GitHub do this, create a yml file and name this file as allure-testng.yml, and copy/paste the content below.

allure-testng-example/.github/workflows/allure-testng.yml
allure-testng.yml

Let’s analyze the file above

Line 20 — Even if an error occurs, go ahead. This is important to have failed tests on the report.

Line 24 — Always run the Allure Report and use the branch gh-pages, let’s see how to do it soon.

Line 35 — Use the generated files to build the report

Line 40 — Increment the current Allure Repost history

4.6. Add UTs

This step is the normal way of work, UTs, ITs, etc. The forked project came with a SimpleTest class.

In this branch, were created 3 classes. You can create as much as you can or as required by your system.

You can add some Allure annotations, I’m using the Feature annotation.

PaymentServiceTest class

5. Running

5.1. Locally

You can the project locally, and for it use the command below

./mvnw clean test -Dmaven.test.failure.ignore=true site io.qameta.allure:allure-maven:serve
Allure Report — locally

5.2. GitHub pipeline

Using the pipeline, the report is triggered by a new code or to rerun the last action.

In this example, I push a new code.

GitHub — Pipeline

After the build pipeline is completed, the action to update the gh-pages is started.

GitHub — Actions page
GitHub — Pages completed

Open the last workflow pages build and deployment to access the link generated to open the report. The link is inside the box deploy.

GitHub — Actions

Voilà, the report is generated and available :)

Allure Report

Another option is open via the link, for this repo the link is luizgustavocosta.github.io/allure-testng-example/index.html

6. References

--

--

Luiz Gustavo De O. Costa

Hey friend!! I’m Luiz Gustavo, a Java developer and I’m here to learn and write about Java, tests and good practices