[英]How to sequence your test cases using ExecutorService unit testing
我正在使用ExecutorService运行并行的junit测试。 每个测试都使用一个随机数生成器来标识自己并独立于其他测试运行。 我的情况就是这样
我知道我可以使用公共静态变量来保存和恢复来自test1的数据。 关于如何整齐地做任何想法。 不想在工作的第一天给人留下不好的印象。
下面的示例代码
public class TestCases {
static ExecutorService exe ;
public static void main(String[] args) throws Throwable {
test1() ;
test2() ;
test3() ;
}
public static void test1() {
exe = Executors.newCachedThreadPool() ;
for (int i = 0 ; i < 10 ; i++) {
Test1 test1 = new Test1() ;
exe.execute(test1) ;
}
exe.shutdown() ;
while(!exe.isShutDown()) {
}
}
//same for test2 and test3
}
一种方法是将Test1和Test2合并为Test3的子集。 实际上所有这些都可以成为Test4。 这样,您将仅测试1个特定方案。 我建议您以一种创建基于场景的测试的方式进行思考。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.