[Cucumber-jvm] Cannot inject @Test with parameters CucumberFeatureWrapper

32 views
Skip to first unread message

Wong Peter

unread,
Apr 11, 2018, 10:32:50 PM4/11/18
to Cukes
I running a project using BDD Cucumber and TestNG but it encounter error at below.

Cannot inject @Test annotated Method [feature] with [interface cucumber.api.testng.CucumberFeatureWrapper].
For more information on native dependency injection please refer to http://testng.org/doc/documentation-main.html#nativ
e
-dependency-injection


I know that @Test method can only have @ITestContext annotation. How to run my feature file?

I using version 2.4.0 for cucumber-jvm. Any concrete examples?

@CucumberOptions(
        features
= "src/Feature",
        glue
= {"Step_Definitions"},
        plugin
= {
               
"pretty",
               
"html:target/cucumber-reports/cucumber-pretty",
               
"json:target/cucumber-reports/CucumberTestReport.json",
               
"rerun:target/cucumber-reports/rerun.txt"
})
public class TestRunner {
   
private TestNGCucumberRunner testNGCucumberRunner;
   
private ExtentReportManager reportMgr;
   
private PropertiesManager pm;
   
   
@BeforeTest(alwaysRun = true)
   
public void setUp() throws Exception {
        testNGCucumberRunner
= new TestNGCucumberRunner(this.getClass());
       
        pm
= PropertiesManager.createInstance();
        reportMgr
= ExtentReportManager.createInstance();
       
       
WebDriverManager.createDriver();
   
}
 
   
@Test(groups = "cucumber", description = "Runs Cucumber Feature"/*, dataProvider = "dataProvider"*/)
   
public void feature(CucumberFeatureWrapper cucumberFeature) {
   
//ITestContext context
    testNGCucumberRunner
.runCucumber(cucumberFeature.getCucumberFeature());
   
}
   
 
 
   
/*@DataProvider(name = "dataProvider", parallel = true)
    public Object[][] features() {
        return testNGCucumberRunner.provideFeatures();
    }*/

 
   
@AfterTest(alwaysRun = true)
   
public void tearDown() throws Exception {
    reportMgr
.getExtent().flush();
        testNGCucumberRunner
.finish();
   
}



Please help. Thanks. 



Wong Peter

unread,
Apr 12, 2018, 4:06:07 AM4/12/18
to Cukes
Problem solved. 

MP Korstanje

unread,
Apr 12, 2018, 10:28:42 AM4/12/18
to Cukes
Nothing more annoying then finding a post with your problem that has been solved, but still without an answer. :)

For reference cucumber JVM keeps an examples section in the source code:

https://github.com/cucumber/cucumber-jvm/tree/master/examples/java-calculator-testng
Reply all
Reply to author
Forward
0 new messages