wood burning stoves*
The moose likes Ant, Maven and Other Build Tools and the fly likes parameterized TestNG factory initialization using Maven Surefire plugin Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » Ant, Maven and Other Build Tools
Bookmark "parameterized TestNG factory initialization using Maven Surefire plugin" Watch "parameterized TestNG factory initialization using Maven Surefire plugin" New topic
Author

parameterized TestNG factory initialization using Maven Surefire plugin

Stefan Strobel
Greenhorn

Joined: Aug 28, 2013
Posts: 2
Hi experts,

I'm pretty new to all Maven, TestNG and the Surefire plugin that connects both.
So for, I can execute tests using the testng.xml file and groups/classes defined in the pom. Now I need to implement a factory pattern that will run all test methods for one (or more) classes.
Currently I have the following setup:
I have a test class which extends a base class to set up the environment (I'm running GUI tests with Selenium Webdriver). In the TestBase class, I prepare a number of different browsers. The Tests are grouped and my surefire plugin calls a specic group. Upon initialization of the test object containg the test methods, a factory shall provide the browsers.

Hm difficult to show that in a compact way.
But when I run my maven script the following happens:
org.testng.TestNGException:
Can't invoke public void org.test.pages.HomePageTest.testTitleMatching() throws java.lang.InterruptedException: either make it static or add a no-args constructor to your class


Currently my code looks like the following:


My parent class:


here comes my factory:


and my surefire plugin configuration:


So can anyone image what is going wrong? I read in other posts that I have to use the factory pattern (what actually do, don't I?). Wild guesses?

Thanks!
Stefan
Peter Johnson
author
Bartender

Joined: May 14, 2008
Posts: 5812
    
    7

You could follow the second part of the error messages: "add a no-args constructor to your class"

The constructor you do have takes a parameter and I suspect that TestNG is ignoring the @Factory annotation (is that a TestNG annotation? if not, is it an annotation of a TestNG extension and if so did you properly configure the extension?)


JBoss In Action
Stefan Strobel
Greenhorn

Joined: Aug 28, 2013
Posts: 2
Hi Peter,

thanks for your answer. I managed to get it work two days ago with another approach. Turns out I missed one of the many possible variations:





It works like a charm now. Even with an args-constructor. Hope this helps anyone else
Vasyl Lenko
Greenhorn

Joined: May 21, 2014
Posts: 1
I had the same issue. Solution: DataProvider method should return Object[][] instead of Iterator<Object[]>.
 
 
subject: parameterized TestNG factory initialization using Maven Surefire plugin
 
Similar Threads
Testng And Maven Error Log. Can not understand
unabled to correctly excecute integration-test
How does surefire work
Unable to run DataSource related testcases in TestNG with command prompt
Maven - Could not reserve enough space for object heap error