I am trying to check the environment where I will be running my test before setting dataProvider
name in my test method.
public class AssignmentSOAPTest {
private static final String ctdataProvName=System.getProperty("env");
@BeforeClass
public void setUp() {
}
@Test(dataProvider = ctdataProvName, dataProviderClass CCCAssignmentSOAPDataProvider.class)
@Feature("FullCCCAssignment")
public void tc01FullCCCAssignment(int a,int b,int c) {
System.out.println("These are the number provided by Data Provider "+ a+"," +b+","+c);
}
}
In this case since my @Test Method is giving me an error: Attribute value must be constant. I discovered this is due because of the way I am setting the constant is not the correct way. I tried different ways to check the environment before setting the constant but could not figure it out. Is there a way to do this?
The reason I would like to check the environment before setting the name is because that way I will need fewer @Test
methods in my testScript. I have 4 different environments as well as 10 different test cases. The test cases will be the same among environments but data will be different.
My Data provider class looks like this(did not add all environments and data will be different):
@DataProvider (name = "ct-environment-data-provider")
public Object[][] ctDPMethod (Method m){
switch (m.getName()) {
case "tc01FullCCCAssignment":
return new Object[][] {{2, 3 , 5}};
case "minimumAssignment":
return new Object[][] {{2, 3, -1}};
case "updateAssignment":
return new Object[][] {{1, 3, -1}};
case "cancelAssignment":
return new Object[][] {{3, 3, -1}};
case "saveAssignment":
return new Object[][] {{8, 3, -1}};
case "openShopAssignment":
return new Object[][] {{5, 3, -1}};
case "casualtyAssignment":
return new Object[][] {{6, 3, -1}};
}
return null;
}
@DataProvider (name = "int-environment-data-provider")
public Object[][] intDPMethod (Method m){
switch (m.getName()) {
case "tc01FullCCCAssignment":
return new Object[][] {{1, 1 , 5}};
case "minimumAssignment":
return new Object[][] {{2, 3, -1}};
case "updateAssignment":
return new Object[][] {{1, 3, -1}};
case "cancelAssignment":
return new Object[][] {{3, 3, -1}};
case "saveAssignment":
return new Object[][] {{8, 3, -1}};
case "openShopAssignment":
return new Object[][] {{5, 3, -1}};
case "casualtyAssignment":
return new Object[][] {{6, 3, -1}};
}
}