TestVagrant

Allure Server Standalone: Your Path to Real-Time Test Reporting

Blog

How to build a Real-time Test Case Monitoring solution using logs?

In the dynamic world of software development, it’s super important to test and report issues to deliver quality products. If you’ve been doing software testing, you’ve probably encountered various testing frameworks, each with its own features and reporting mechanisms. That’s where Allure Server Standalone comes into play — as your trusted companion in test reporting.

But what exactly Allure Server Standalone is?

Allure Server Standalone is a handy tool that pairs well with Allure Test Report framework. It’s like a user-friendly dashboard that gives a clear view of your test results from different testing tools. Basically, it offers an easy-to-use interface, so you and your team can see and interpret your test reports without diving into allure command lines or any other technical stuff. In short, it serves as your go-to platform for straightforward test reporting and analysis.

Key features of Allure Server Standalone

  • Centralized Repository & Web Interface: It acts as a central hub for storing and organizing test results generated by different testing frameworks. Additionally, it offers a user-friendly web interface accessible to all team members, whether they have technical expertise or not.
  • Teamwork & Collaboration: Allure Server Standalone encourages teamwork by providing a shared platform where team members can view and discuss test results.
  • Historical Test Data & Instant Updates: It keeps a record of past test results so teams can see and track trends. Plus, as new tests are executed, it gives instant updates, keeping everyone informed about the testing progress.
  • Support for Multiple Testing Frameworks: Allure Server Standalone seamlessly works with various testing frameworks, allowing us to stick with our favorite testing tools.

Approaches to using Allure Framework

As we all know, Allure Framework generates eye-catching reports for automated test cases. However, there are three ways to use this tool effectively –

  1. Set up the server which can run on a tool like Jenkins to access reports remotely.
  2. Using allure command line interface and some terminal commands to see reports locally.
  3. Docker container will bundle this application and its dependencies, including libraries and configurations into a single package called a “container” which is like a standalone environment that has everything the application needs to run.

The first two ways can be a bit of a hassle and that’s where the Docker container comes to the rescue which allows us to access the latest report by simply mounting your allure-results directory (linking your ‘allure-results’ directory to allure container volume) using shell script file and voilà! No need for a complex setup or commands — just get straight to your report hassle-free.

Now that you’re familiar with the immense power and flexibility that a standalone Allure server offers, it’s time to roll up your sleeves and get your hands dirty with code.

Let’s begin by cloning the allure-server-standalone-template project which is based on Java and TestNG. This project comes with a basic setup of test cases designed to generate real-time, refreshable reports right on your local machine.

Once you’ve cloned the repository, the next step is to get Docker up and running on your machine. If you haven’t already installed it, you can download it from here.

After installing Docker, open Docker Desktop and keep it running throughout the entire process. Next, navigate to Docker Hub and obtain the Allure Docker service image required for our project. You can pull this image directly from your terminal using the following command –

				
					docker pull frankescobar/allure-docker-service

				
			
With Docker set up, let’s proceed to execute our test cases. Open the cloned repository in IntelliJ or any IDE that supports Maven projects. Now, build the cloned project using — “mvn clean install”. Next, Execute the test cases by running the following Maven command in terminal window separate from the one where the Docker container is currently running. (You can execute any set of test cases you prefer; simply mention the class file in the command and ensure that allure-results are generated after execution).
				
					mvn clean test -Dtest=com.example.SetOfTwoTestCase
				
			

Upon successful test execution, you’ll notice that an allure-results directory has been generated at the root level of our project. This directory will be mounted so that Allure Docker service can track the latest results.

Now, launch the Allure service by running the following Docker command:

				
					docker run -p 5050:5050 -e CHECK_RESULTS_EVERY_SECONDS=3 -e KEEP_HISTORY=1 \
frankescobar/allure-docker-service
				
			

This Docker command runs a container with the ‘frankescobar/allure-docker-service’ image. It maps port 5050 from the host to port 5050 in the container, making the service accessible on the host machine. Additionally, it sets environment variables: “CHECK_RESULTS_EVERY_SECONDS” variable determines how often the service should check for new test results, and “KEEP_HISTORY” specifies whether to keep historical test data or not.

Next, We will be using a shell script file to interact with Allure server. Basically, this script is required to automate the process of managing and transmitting test results to an Allure server and it is particularly useful in scenarios where you have frequent test runs and want to streamline the reporting and visualization of the latest test results

				
					#!/bin/bash
# This directory is where our local results are stored and it is generally named as `allure-results`
ALLURE_RESULTS_DIRECTORY='allure-results'

# This url is where the Allure container is deployed. Use `localhost` when allure server is running in local
ALLURE_SERVER='http://localhost:5050'

# Project ID according to existent projects in your Allure container - Check endpoint for project creation >> `[POST]/projects`
PROJECT_ID='default'
#PROJECT_ID='my-project-id'

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
FILES_TO_SEND=$(ls -dp $DIR/$ALLURE_RESULTS_DIRECTORY/* | grep -v /$)
if [ -z "$FILES_TO_SEND" ]; then
  exit 1
fi

FILES=''
for FILE in $FILES_TO_SEND; do
  FILES+="-F files[]=@$FILE "
done

set -o xtrace
echo "------------------CLEAN-RESULTS------------------"
curl -X GET "$ALLURE_SERVER/allure-docker-service/clean-results?project_id=$PROJECT_ID"

echo "------------------SEND-RESULTS------------------"
curl -X POST "$ALLURE_SERVER/allure-docker-service/send-results?project_id=$PROJECT_ID" -H 'Content-Type: multipart/form-data' $FILES -ik
				
			

In the provided repository, you’ll find a shell script file named ‘report_generation.sh’ which contains the script mentioned above. we just need to specify the directory where local results, typically named ‘allure-results, are stored, and the URL of the Allure server (use ‘http://localhost:5050’ when running locally). The script then locates and prepares files for transmission to the server. It sends a request to clean existing results and upload the new ones to the Allure service using cURL commands.

Now, open a new terminal window in your IDE and execute ‘report_generation.sh’ file using command — “./report_generation.sh”.If you encounter a ‘permission denied’ error, resolve it by executing the command ‘chmod +x report_generation.sh’ to grant execution permission to the file. Afterwards, you can run the ‘report_generation.sh’ script again using the command ‘./report_generation.sh’.

You’re almost there. Just fire up your web browser and head over to http://localhost:5050/allure-docker-service/latest-report to check out your latest Allure report.

And here’s the best part: After executing another test class with the command ‘mvn clean test -Dtest=com.example.SetOfFourTestCase’ and afterward executing the ‘report_generation.sh’ file, simply refresh your browser. Upon refreshing your browser, you’ll see the report update in real time. It may take a few seconds to render the latest data, but your patience will be rewarded with an up-to-date view of your test cases. Congratulations, you’ve just experienced the power and convenience of using a standalone Allure server for real time test reporting!

Did you know? Allure has this really useful feature where you can easily see the history of your test reports. All you’ve to do is click on the Allure logo, and it’ll take you to a page at “http://localhost:5050/allure-docker-service/projects/default“. Here, you’ll find a list of html files, each one presenting a report from previous tests, making it easy to track your testing history.

So far, we have seen how to generate and view Allure reports locally using a Docker container and shell script file. However, these reports are confined to our local machine, making them inaccessible to other team members or stakeholders. The solution? Hosting our Allure reports on a cloud platform!

In our previous discussions, we delved deep into leveraging Allure Server Standalone for local test reporting. Now, we’re scaling that up, moving from a local environment to the cloud and integrating the entire process into a CI/CD pipeline.

The cloud is not just a buzzword; it’s a way to ensure that our entire team, irrespective of their location, can access and view our Allure reports. By deploying the Allure service in a cloud container, we transform our reports from being a local asset to a globally accessible resource.

In order to harness the advantages of cloud service, we must deploy our Docker container with ‘frankescobar/allure-docker-service’ image to a cloud-based platform. For those already acquainted with Docker, think of it as taking your local container orchestration to a cloud level where it can be accessed publicly. Again, the command to launch the container remains the same as shown below and the report files will be sent to this service via the shell script we discussed earlier.

				
					docker run -p 5050:5050 -e CHECK_RESULTS_EVERY_SECONDS=3 -e KEEP_HISTORY=1 \
frankescobar/allure-docker-service
				
			

Post-deployment, you’re assigned a public URL for your Allure service. This URL serves as a centralized dashboard, where reports can be accessible to the entire team.

Automating Report Uploads with a Shell Script

The true power of automation in a CI/CD pipeline lies in scripts. A well-crafted script can save hours of manual work. In our scenario, a shell script will take care of pushing our Allure results to the deployed Docker container. Our shell script file will remain mostly unchanged, as previously discussed, with just a couple of modifications.

  • Update ALLURE_RESULTS_DIRECTORY: This should point to the directory where your CI/CD pipeline stores test results.
  • Replace ALLURE_SERVER: Use the public URL where your Allure Docker service is deployed. This URL will serve as the centralized access point for your team’s Allure reports.

The shell script can be integrated into your project or workflow in two primary ways:

  1. Project-Level Integration: Place the shell script at the root directory of your project and execute it programmatically during the teardown process after running your test cases
  2. CI/CD Pipeline Integration: Alternatively, you can include this shell script directly in your CI/CD pipeline, typically executing it at the ‘post-build’ or ‘tear-down’ stage.

The choice largely depends on your specific needs. However, integrating it directly into the CI/CD pipeline is generally more efficient for teams that rely heavily on continuous integration and deployment. It streamlines the entire process and makes sure that the most recent test results are always pushed to the Allure service without manual intervention.

In conclusion, Allure Server Standalone streamlines the often complex process of software testing and reporting. Its user-friendly interface and cloud-ready capabilities make it a go-to solution for teams looking for seamless collaboration and data-driven insights. By integrating it into your CI/CD pipeline, you elevate test reporting to a new level of efficiency and accessibility.

Thank you for exploring this versatile tool !!
Happy Learning !!!

References :
https://github.com/fescobar/allure-docker-service
https://docs.docker.com/get-started/overview/

Share This Article

Other Related Articles

Scroll to Top