View Test Results in Grafana - Part 2

DZone 's Guide to

View Test Results in Grafana - Part 2

In this article, see how to upload test results to Influx DB using TestNG Listeners and configure Grafana to view the data

· Java Zone ·
Free Resource

In the 1st part of this series, we set up Grafana and InfluxDB for our test reports. Now, as a follow up to that, we are going to see how to store test results in database and how to view the results in Grafana.

I am going to use Scala with TestNG framework in this demo. For those who are working in Java, it is mostly the same as Scala.

InfluxDB Dependency 

As the 1st step, add InfluxDB dependency to the project. Add the below line to your build.sbt file.


Add the below plugin to the plugins.sbt:


Add Listeners

In the test project, now we are going to add TestNG Listeners to store data in InfluxDB. In the below code, I had

  •  implemented all methods of an interface "ITestListener"

In the postTestMethodStatus and postTestRunStatus methods, I am creating 2 measurements (tables) testmethod and testrun. 1st one is to store the tests and 2nd one is to store the runs. 

The listeners will be called for events like on test passed, on test failed, on test skipped and at the end of test run etc. 

I am updating "testmethod" table after every passed/ failed/ skipped test case and am updating the "testrun" table after every test run. 


Create connection to DB and update the database using the below code. 


Include listeners to your testng.xml file.


Now run your tests. 


After the test execution, you can see the data of your tests populated in testrun and testmethod tables as below.

Our data is ready. 

Data is ready

Configure Grafana

Now let's take a case I need a graph that should show the number of runs that are passed and failed. To draw a chart, for me, data from "testrun" table is enough. 

In your Grafana home page, click on "Build a dashboard" or "Create" icon from left pane. This will create an empty dashboard for you. Now, click on "add panel" icon at the header. We will be adding visual representations in the panels.

Adding visualizations

Click on choose vizualisation and choose Pie-Chart. If you don't find the plugin, follow this to install.

Installing plugin

Set up the query like below, as per your requirement. 

Setting up the requirement

The graphs are real-time and will be updated as soon as there is data-change. 

Dashboard with some other graphs 

Dashboard with other graphs

That's it, now you don't need to share test-results with your clients or to your team through an email or in a shared folder. Results will be updated here after every test-run.

You can find sample project here.

Happy Reading!!

automation testing, grafana, influxdb, listeners, sbt, scala, software testing, test automation framework, test results, testng

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}