0

enter image description here

Please refer to attached screen shot, with Junit one can see each of the scenario steps results but with TestNG it's not showing the same.

Is it possible with TestNG as well ? Am I missing any configuration, with JUnit it just works.

vikramvi
  • 3,312
  • 10
  • 45
  • 68

1 Answers1

2

After doing some research I've found that there are several tickets for this and similar questions on SO. Maybe the following will provide more info.

At the moment, for cucumber-jvm release version 1.2.5, features are run as a single TestNG test (as you can see in the image below)

enter image description here

This ticket was open and not long ago and they have added the functionality to run a TestNG test for each scenario (pull request here).

Because these changes are not released yet, in order to get TestNG to run for each scenario, you have to do a few things:

  • project used to test this -> here. (I used IntelliJ for this project, same thing can be done in Eclipse)
  • update pom.xml so you can use the master branch of cucumber-jmv, and therefore have the latest changes. Below are the changes I've made.

<repositories>
    <repository>
        <id>sonatype-snapshots</id>
        <url>https://oss.sonatype.org/content/repositories/snapshots</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
    </repository>
</repositories>

<parent>
    <groupId>io.cucumber</groupId>
    <artifactId>cucumber-jvm</artifactId>
    <version>2.0.0-SNAPSHOT</version>
</parent>

<artifactId>java-calculator-testng</artifactId>
<packaging>jar</packaging>
<name>Examples: Java Calculator TestNG</name>

<dependencies>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-jvm-deps</artifactId>
        <version>1.0.5</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>2.0.0-SNAPSHOT</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-testng</artifactId>
        <version>2.0.0-SNAPSHOT</version>
        <scope>compile</scope>
        <exclusions>
            <exclusion>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
</dependencies>

  • go to src/test/java, open RunCukesTest and run it. Here are the results:

enter image description here

I'm sure you can apply the testng.xml to make it run as you wish.

Unfortunatelly for now, steps are still not shown. Will probably be added in future releases, it's the next logical step.

Hope this answers your question.

Daniel Fintinariu
  • 2,733
  • 1
  • 14
  • 16
  • I've referred to embedded github project itself to setup TestNG + Cucumber. But even after mentioning class name per your suggestion, result doesn't show each of the steps. Please let me know if it's working at your end ? – vikramvi Aug 10 '17 at 10:22
  • Thanks for this info, isn't this should issue for TestNG github repo instead of cucumber-jvm ? I looked into the ticket but it doesn't talk about this particular issue – vikramvi Aug 10 '17 at 12:16
  • I went ahead and filed the issue https://github.com/cbeust/testng-eclipse/issues/350 – vikramvi Aug 10 '17 at 12:20
  • `cucumber-testng` library is responsible for how the tests are shown, but the ticket you've opened might help to get steps to show. I've updated my answer @vikramvi – Daniel Fintinariu Aug 11 '17 at 08:49
  • I didn't understand how RunCukesTest class picked up basic_arithmetic.feature , can you please clarify ? Per my understanding feature file name needs to be explicitly mentioned along within @CucumberOptions – vikramvi Aug 11 '17 at 10:48
  • 1
    RunCukesTest extends AbstractTestNGCucumberTests which has a DataProvider method that calls `provideScenarios()`. it probably looks for a default location in the same package. Check RuntimOptions class, provided by cucumber. – Daniel Fintinariu Aug 11 '17 at 11:09
  • Thanks for clarifications, I've accepted your answer. – vikramvi Aug 11 '17 at 12:44