I was trying to run multiple test with different parameters sequentially using data providers, basically the scenario is suppose there are 5 test completing a test flow and
So my concern is that all test should run first with first parameter air and then again all test should execute with next parameter "earth"
Here is the output that i got for the input "air" and "earth"
Test-1 with data: Air
Test-2 with data: Air
Test-1 with data: Water
Test-2 with data: Water
Test Class - RandomTest
public class RandomTest {
private String str = "";
public RandomTest(String str) {
this.str = str;
}
@Test
public void firstTest() {
System.out.println("Test-1 with data: "+str);
}
@Test
public void secondTest() {
System.out.println("Test-2 with data: "+str);
}}
Factory class - SampleFactory
public class SampleFactory {
@Factory(dataProvider="dp")
public Object[] createInstances(String str) {
return new Object[] {new RandomTest(str)};
}
@DataProvider(name="dp")
public static Object[][] createData() {
return new Object[][] {
new Object[] { new String("Air") },
new Object[] { new String("Water") }
};
}}
Run the class SampleFactory from testng.xml, Please note: group-by-instances="true"
<suite name="Suite-A" verbose="1">
<test name="test" group-by-instances="true">
<classes>
<class name="tests.SampleFactory"></class>
</classes>
</test>
</suite>
Ref: http://testng.org/doc/documentation-main.html#factories
Ref: http://java.dzone.com/articles/testng-run-tests-sequentially
You can change your parameters without code change, change only testng.xml file.
Your Java class:
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
public class ParameterizedTest1 {
@Test
@Parameters("myName")
public void parameterTest(String myName) {
System.out.println("Parameterized value is : " + myName);
}
}
testng.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Suite1">
<test name="test1">
<parameter name="myName" value="manisha"/>
<classes>
<class name="ParameterizedTest1" />
</classes>
</test>
</suite>
http://www.tutorialspoint.com/testng/testng_parameterized_test.htm
You can use nose-ittr, its a nose extension for supporting parametrized testing.
example:
@ittr(number=[1, 2, 3, 4])
def test_even(self):
assert_equal(self.number % 2, 0)