0
我有List<Map>
,我想根据Lists值编写一个动态测试用例。如何在junit中创建动态测试用例?
我的商业逻辑原样
public List<Map<Object, Object>> listofMap() {
List<Map<Object, Object>> listofmapObj = new ArrayList<Map<Object, Object>>();
Map<Object, Object> map1 = new HashMap<Object, Object>();
map1.put("map1key", "map1value");
Map<Object, Object> map2 = new HashMap<Object, Object>();
map2.put("map2key", "map2value");
Map<Object, Object> map3 = new HashMap<Object, Object>();
map3.put("map3key", "map3value");
listofmapObj.add(map1);
listofmapObj.add(map2);
listofmapObj.add(map3);
return listofmapObj;
}
我的测试接收机类
public class TestCaseCreateListOfMap extends TestCase {
StringBuffer strBuff = new StringBuffer();
String name;
@Test
public void testResultsForListOfMap(){
try {
AddListOfMap obj=new AddListOfMap();
List<Map<Object, Object>> listofmap= obj.listofMap();
for (Map<Object, Object> map : listofmap) {
for (Map.Entry<Object, Object> entry : map.entrySet()) {
System.out.println(entry.getKey() + " - " + entry.getValue());
strBuff.append(entry.getKey() + " - " + entry.getValue());
}
}
}
catch (Exception e) {
// TODO: handle exception
strBuff.append(e.getMessage());
}
if(strBuff.length()>0){
fail("" + strBuff);
}
}
}
现在我需要三种不同的测试案例包含三个地图列表。可能吗?请帮助我。 目前我正在编写测试方法为“testResultsForListOfMap”,但我想要三个不同的测试用例。
感谢 普利文
了解决方案使用测试套件的概念..谢谢:) – 2014-10-28 09:58:25
除了措辞不佳之外,这篇文章不会尝试回答OP的题。 – jpaugh 2016-03-24 17:59:13
@jpaugh可能是你正确的,但它有助于OP,这就是为什么我不删除我的帖子。 – 2016-03-30 21:40:53