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 all test cases should run in sequence suppose in data provider first parameter returned is "air" then all 5 test should run with parameter "air" and then second parameter and so on.
Currently in dataprovider what happens is if supposingly parameters are "air", "earth" then first test executes with both the parameters and then move on to next test.
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".
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 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)
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