I am learning JUnit and I have to test a method multiple times. I have to test the method based on two parameters (Environment and Case#). I am working on two environments where I have to check if the same Case# yields the same results between different environments. This is the test case:
public class AppStartTest
{
/**
* Test method for {@link archive.AppStart#beginOper(java.lang.String)}.
*/
List<String> actualSections = new ArrayList<String>();
List<String> environments = new ArrayList<String>();
List<String> cases = new ArrayList<String>();
@Before
public void prepareTest()
{
environments.add("env1");
environments.add("env2");
cases.add("case1");
//cases.add("case2");
cases.add("case3");
cases.add("case32");
cases.add("case4");
cases.add("emp3");
}
@Test
public void testBeginOper()
{
for (String caseStr : cases)
{
@SuppressWarnings("unchecked")
Map<String, Integer> mapList[] = new HashMap[2];
int i = 0;
for (String env : environments)
{
System.out.println("Starting " + env + "-" + caseStr);
AppStart a = new AppStart();
mapList[i] = a.beginOper(env + "-" + caseStr, true);
printMap(mapList[i++]);
}
//Using assert in this method
compareResults(mapList[0], mapList[1], caseStr);
}
}
}
The result yields as a single test case, but I would be requiring the results as:
testBeginOper[0]
testBeginOper[1]
testBeginOper[2]
.....
I tried using parameterized test cases, but the test method would be executed independently. I have to compare the results between two environments and I would need the method with @Test to return some value (Method should be void) and then assert. Please advise.