Test Diary


Social Profile

Recent Comments

Cucumber-jvm and TestNg Framework

Olufemi Ade-OlusileOlufemi Ade-Olusile


A lot of testers ask me this question a lot.  “Can I implement TestNG to run with my JUnit Maven Cucumber framework?”

The answer is yes you can.

A lot of frameworks are developed using TestNG and you would want such frameworks to drive Cucumber-jvm.  Therefore, the following steps below will allow you use Cucumber successfully with TestNG.

Step 1. Add the following dependency into your Maven pom.xml file.


Step 2. Extend your class running your JUnit Runner with  AbstractTestNGCucumberTests. For example:

import org.junit.runner.RunWith;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import cucumber.api.testng.AbstractTestNGCucumberTests;

@CucumberOptions (
monochrome = true,
features = "src/test/java/features",
plugin = {"pretty", "html:target/cucumber-html-report"},
//glue = " ",
tags = "@testdiary"
public class CukesRunnerTest extends AbstractTestNGCucumberTests {


Step 3.  Insert your test package to run into your testng.xml file. For example:

<test name="Test diary">
<package name="cucumberTraining"/>

Example of a Cucumber test running on TestNG


You can download this Cucumber-jvm TestNg framework from the Testdiary Github.

Click: Cucumber-jvm TestNG Framework

This should solve your problem

Happy testing!!!

“My name is Olufemi Ade-Olusile, and I am a Software Developer in Test. I am the owner of "Test diary" which is aimed at inspiring and teaching software testers.

  • Mirza Asim Baig

    Well ! Nice blog….I have been trying the same but while running my tesrunner file run As TestNG….. getting an error :
    ” cucumber.runtime.CucumberException: java.lang.IllegalArgumentException: key can’t be empty”

    No idea how to solve https://uploads.disquscdn.com/images/6b1b908339ae1c4716fa0186327798eb1d5cdf8b9814a8c38789b803f2efc9e3.jpg

    • @disqus_rOY2yy9MgK:disqus Seems you may have a problem with one of the params. Is this project on Git, so i can get it and find the problem. Do you have any feature with the tag @test1, many questions need to be answered. I guess this exception is being thrown by the resultsListner. Can you upload this project on git and i look at it for you.. Cheers…..

      • Mirza Asim Baig

        Well ! Thanks a ton . I got the solution for it. Actually missed out to pass a value in parameter. My bad !!