2018-03-19
1 背景
当case之间有依赖关系,有依赖关系的case,它们的执行顺序是有限制的。TestNG提供了依赖管理功能
2 基础理论
这个执行顺序可以用拓扑排序算法实现。
只要是有向无环图就能被拓扑排序,拓扑排序维基典型实现算法:
L ← Empty list that will contain the sorted elements S ← Set of all nodes with no incoming edges while S is non-empty do remove a node n from S insert n into L foreach node m with an edge e from n to m do remove edge e from thegraph if m has no other incoming edges then insert m into S if graph has edges then return error (graph has at least one cycle) else return L (a topologically sorted order)
TestNG依赖管理功能
- dependsOnMethods
@Test public void serverStartedOk(){} @Test(dependsOnMethods={ "serverStartedOk" }) public void method1() {}