package test;
import org.apache.log4j.Logger;
import org.testng.annotations.*;
import org.testng.annotations.Test;
public class TestTest
{
private String param;
@Factory( dataProvider = "prov" )
public TestTest( String param )
{
this.param = param;
}
@DataProvider( name = "prov" )
public static Object[][] dataProvider()
{
System.out.println( "[" + Thread.currentThread().getId() + "] Provide data" );
return new Object[][] {
{ "One" },
{ "Two" },
{ "Three" },
};
}
@BeforeClass
public void prepare()
{
System.out.println( "[" + Thread.currentThread().getId() + "] Prepare " + param );
}
@Test
public void test1()
{
System.out.println( "[" + Thread.currentThread().getId() + "] Test1 " + param );
}
@Test( dependsOnMethods = "test1" )
public void test2()
{
System.out.println( "[" + Thread.currentThread().getId() + "] Test2 " + param );
sleep();
}
@AfterClass
public void clean()
{
System.out.println( "[" + Thread.currentThread().getId() + "] Clean " + param );
}
private void sleep() {
try {
Thread.sleep(10000);
} catch (Exception ignored) {}
}
}
With the following testng.xml:
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Suite" parallel="instances" thread-count="5" group-by-instances="true">
<test name="Tests">
<classes>
<class name="test.TestTest" />
</classes>
</test>
</suite>
public class FactoryInstances {
private String param;
@Factory (dataProvider = "prov")
public FactoryInstances(String name, int value) {
this.param = name + "(" + value + ")";
System.out.println("[" + Thread.currentThread().getId() + "] instance created with [" + param + "]");
}
@DataProvider (name = "prov", parallel = true)
public static Object[][] dataProvider() {
System.out.println("[" + Thread.currentThread().getId() + "] Provide data");
return new Object[][] {
{"One", 1},
{"Two", 2},
{"Three",3},
};
}
@BeforeClass
public void prepare() {
System.out.println("[" + Thread.currentThread().getId() + "] Prepare " + param);
}
@Test
public void test1() {
System.out.println("[" + Thread.currentThread().getId() + "] Test1 " + param);
}
@Test (dependsOnMethods = "test1")
public void test2() {
System.out.println("[" + Thread.currentThread().getId() + "] Test2 " + param);
sleep();
}
@AfterClass
public void clean() {
System.out.println("[" + Thread.currentThread().getId() + "] Clean " + param);
}
private void sleep() {
try {
TimeUnit.SECONDS.sleep(10);
} catch (Exception ignored) {
}
}
}
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Suite" parallel="instances" thread-count="30" data-provider-thread-count="10" group-by-instances="true"
verbose="2">
<test name="Tests">
<classes>
<class name="organized.chaos.forums.testng.FactoryInstances"/>
</classes>
</test>
</suite>
--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users+unsubscribe@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.