Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

io.cucumber.junit.CucumberOptions vs io.cucumber.testng.CucumberOptions vs cucumber.api.CucumberOptions which one should i choose

I am new to cucumber.I am trying to run cucumber feature files using testng in maven project. for which, in my pom.xml file, I have dependencies for TestNG,cucumber,junit,cucumber junit,cucumber java,selenium java

I have imported CucumberOptions from io.cucumber.junit.CucumberOptions and when i used attribute format , eclipse is throwing error that format The attribute format is undefined for the annotation type CucumberOptions Also eclipse is giving me options to import CucumberOptions from 3 different classes namely

io.cucumber.junit.CucumberOptions
io.cucumber.testng.CucumberOptions
cucumber.api.CucumberOptions

I have 2 questions.
  1. All these 3 packages seems do not support format attribute, what should i do , if i want to have below o/p

    format = {
    "pretty",
    "html:target/cucumber-reports/cucumber-pretty",
    "json:target/cucumber-reports/CucumberTestReport.json",
    "rerun:target/cucumber-reports/rerun.txt"
    } 
    
  2. I am completely clue less when to use each of these package for what scenario . Please help me.

tried googling for info, few blogs said format is deprecated and now we need to use pretty, at the same time few say we should use format for generating output in different formats

package com.qa.testngcucumberrunner;
import io.cucumber.junit.CucumberOptions;
@CucumberOptions(
dryRun=false,
monochrome=true,
strict=true,
features={"./src/test/resources/com/qa/features"},
glue={"com.qa.stepdef"},
plugin={"json:target/cucumber- 
reports/CucumberTestReport.json"},
format = {
"pretty",
"html:target/cucumber-reports/cucumber-pretty",
"json:target/cucumber-reports/CucumberTestReport.json",
"rerun:target/cucumber-reports/rerun.txt"
} 
)
public class TestRunner {}

Expectation: Want to know when should i use which import Also want to know what should i do to get report in html,json,return formates as mentioned in TestRunner file

like image 953
Rajaji Avatar asked Oct 16 '22 11:10

Rajaji


1 Answers

I am new to cucumber.

Have a look at the https://cucumber.io/docs/guides/10-minute-tutorial/

I am trying to run cucumber feature files using testng in maven project. for which, in my pom.xml file, I have dependencies for TestNG,cucumber,junit,cucumber junit,cucumber java,selenium java

Each dependency provides a bit of functionality. You should only add dependencies for the bits you need. For example cucumber-java dependency gives you the @Given, @When, @Then annotations. The cucumber-junit and cucumber-testng modules provide integration with JUnit and TestNG respectively.

It is unlikely that you are using both. So if you are testing with TestNG you should use cucumber-testng and cucumber-java and remove the dependency on cucumber-junit. The other way around if you are testing with JUnit you should use cucumber-junit and cucumber-java and remove cucumber-testng.

Want to know when should i use which import

Your IDE should tell you that cucumber.api.CucumberOptions is deprecated. So if you are using JUnit you use io.cucumber.junit.CucumberOptions and if using TestNG io.cucumber.testng.CucumberOptions.

All these 3 packages seems do not support format attribute

The format attribute was replaced with plugin.

Now I can't work out if you are using JUnit or TestNG so you'll have to pick:

  • https://github.com/cucumber/cucumber-jvm/tree/main/junit
  • https://github.com/cucumber/cucumber-jvm/tree/main/testng
like image 72
M.P. Korstanje Avatar answered Oct 21 '22 07:10

M.P. Korstanje