RestFuse的研究(一) HttpJunitRunner的实现
???????? 在RestFuse是一种针对Rest WebService和Http的请求的单元测试的junit扩展的.既然是Junit的扩展肯定有相关的Runner对象,在RestFuse中主要为HttpJunitRunnner对象,继承自BlockJUnit4ClassRunner重写部分方法.因为RestFuse在测试单元方法中采用的时自己的注解HttpTest,所以需要重写获取单元测试方法computeTestMethods.
?
BlockJUnit4ClassRunner源代码方法如下:
protected List<FrameworkMethod> computeTestMethods() { return getTestClass().getAnnotatedMethods(Test.class); }
?HttpJunitRunnner重写之后为:
protected List<FrameworkMethod> computeTestMethods() {ArrayList result = new ArrayList();result.addAll(getTestClass().getAnnotatedMethods(HttpTest.class));List testAnnotatedMethods = getTestClass().getAnnotatedMethods(Test.class);for (FrameworkMethod method : testAnnotatedMethods) {if (!(result.contains(method))) {result.add(method);}}Collections.sort(result, new HttpOrderComparator());return result;}
?