You are on page 1of 3

Factory & DataProvider: make reports per

object/test

up vote
0 down I have a class that implements several functional tests over an object. This object is
vote
instantiated through Properties file that sets its internal configuration. I would like
favorite to apply the same tests over different configurations, and get reports per
configuration. Is that possible with TestNG?
I created a dataprovider (StandardConfigurationsDataProvider), that returns
Object[] of Object[] { name, property }, where name is the name of the
config I'm using. Then, I have a class holding tests, that implements a factory on the
constructor, called SingleOperationFunctionalityTest (that also inherits ITest,
so I can set the name). There are 10 tests in it, and I used dependsOnMethod to
create causal dependencies between tests.
However, when I run this from eclipse, as soon as TestNG starts exercising the
second configuration, I get test failures, because it runs all objects in parallel. If I
run only a single configuration (any of generated, using indices with a single
element), everything succeeds.
In addition, as if TestNG "collates" all configurations on a single method (annotated
by @Test) as a single test. I would like to have each configuration reported
separately, probably grouped by configurations. Is it possible to do such thing? (less
important) Is it possible to run one SingleOperationFunctionalityTest at a
time?
This would be the outline of my code:
public class StandardConfigurationsDataProvider {

@DataProvider(name = "stdconfs", parallel = false)


public static Object[][] createConfigs() { ... }

public class SingleOperationFunctionalityTest implements ITest


{
@Factory(dataProvider="stdconfs",
dataProviderClass=StandardConfigurationsDataProvider.class)
public SingleOperationFunctionalityTest(String testName,
Properties p)
{ ... }
@Test
public void testInitialization() { ... }

Employee-Personal

@Test(dependsOnMethods = "testInitialization")
public void testContainerOperations() { ... }
@Test(dependsOnMethods = { "testInitialization",
"testContainerOperations" })
public void testStore() { ... }
....
}

update
I managed to get what I want, through a convoluted process. Essentially, what I did
is to create a new class BasicFunctionalityTest, that does the following:
public class BasicFunctionalityTest
{
private static XmlSuite createSuite()
{
XmlSuite suite = new XmlSuite();
suite.setName("BasicFunctionalityTestSuite");
Object[][] tests =
StandardConfigurationsDataProvider.createConfigs();
int counter = 0;
for (Object[] to: tests)
{
Map<String, String> params = new HashMap<String, String>();
params.put("configNum", Integer.toString(counter));
XmlTest test = new XmlTest(suite);
test.setName((String)to[0]);
test.setParameters(params);
List<XmlClass> classes = new ArrayList<XmlClass>();
classes.add(new
XmlClass("com.my.package.SingleOperationFunctionalityTest"));
test.setXmlClasses(classes);
}

counter++;

return suite;
}
public static void main(String[] args)
{
System.err.println(createSuite().toXml());
}

}
Then, I plugged the output of toXml to a file called testng-basic.xml and run that
in Eclipse.

Employee-Personal

Is it possible to skip copy/pasting the output to a file, and run this directly in
Eclipse, with nicely presented output?

Employee-Personal

You might also like