亚洲好骚综合-亚洲黄色录像-亚洲黄色网址-亚洲黄色网址大全-99久久99久久-99久久99久久精品国产

您的位置:軟件測試 > 開源軟件測試 > 開源單元測試工具 > junit
Junit使用及其原理分析
作者:alighters 發布時間:[ 2016/9/13 10:53:28 ] 推薦標簽:單元測試 Junit

  其會調到一個 run(Runner runner) 的方法,而 Runner 是一個抽象類,其實現針對不同的平臺又有好多個。這里主要提及兩個,一個是 Junit4ClassRunner,它是 4.4 版本及之前的采用的,之后被廢棄掉了,而采用了繼承實現抽象類 ParentRunner 的 BlockJUnit4ClassRunner 類,它在 4.5 之后被采用。這里主要查看后者,先看 ParentRunner 對其接口 Runner 中方法 run 的實現:
@Override
public void run(final RunNotifier notifier) {
EachTestNotifier testNotifier = new EachTestNotifier(notifier,
getDescription());
try {
Statement statement = classBlock(notifier);
statement.evaluate();
} catch (AssumptionViolatedException e) {
testNotifier.addFailedAssumption(e);
} catch (StoppedByUserException e) {
throw e;
} catch (Throwable e) {
testNotifier.addFailure(e);
}
}
  其中,主要通過 classBlock 方法生成的 Statement 的 evaluate來進行調用,先看它是怎么生成的:
  protected Statement classBlock(final RunNotifier notifier) {
  Statement statement = childrenInvoker(notifier);
  if (!areAllChildrenIgnored()) {
  statement = withBeforeClasses(statement);
  statement = withAfterClasses(statement);
  statement = withClassRules(statement);
  }
  return statement;
  }
  這里主要的方法 childrenInvoker 會調用一個抽象的方法 protected abstract void runChild(T child, RunNotifier notifier);,它則是由子類來實現。另外看到的是,當測試類中的測試方法都沒有被忽略的時候,則會使用 with對應的三個方法來添加其獲取注解 BeforeClass,AfterClass,ClassRule對應的信息,并添加至其調用的 statement中。
  接下來查看 BlockJUnit4ClassRunner 的 runChild的實現:
  @Override
  protected void runChild(final FrameworkMethod method, RunNotifier notifier) {
  Description description = describeChild(method);
  if (isIgnored(method)) {
  notifier.fireTestIgnored(description);
  } else {
  runLeaf(methodBlock(method), description, notifier);
  }
  }
  其中,若是添加了 @ignore的注解,則不會得到調用。看看 methodBlock方法都干了什么:
protected Statement methodBlock(FrameworkMethod method) {
Object test;
try {
test = new ReflectiveCallable() {
@Override
protected Object runReflectiveCall() throws Throwable {
return createTest();
}
}.run();
} catch (Throwable e) {
return new Fail(e);
}
Statement statement = methodInvoker(method, test);
statement = possiblyExpectingExceptions(method, test, statement);
statement = withPotentialTimeout(method, test, statement);
statement = withBefores(method, test, statement);
statement = withAfters(method, test, statement);
statement = withRules(method, test, statement);
return statement;
}
  在這個 statement 的獲取中,通過使用組合的方式,會這個 statement 添加 Before,After 及其它 Rule 的鏈式調用,后生成一個 statement 來返回。
  總結
  可以看出 Junit 是一個簡單而又強大的庫,不然不會經久不衰。其簡單的實現但又強大的功能已經基本滿足我們絕大多數的需求。但在這里還有一個疑問是不知道 Junit 是如何繼承到 Android Studio 的 IDE 中,并是如何直接調用我們的測試方法或者測試類的?

上一頁12下一頁
軟件測試工具 | 聯系我們 | 投訴建議 | 誠聘英才 | 申請使用列表 | 網站地圖
滬ICP備07036474 2003-2017 版權所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd
主站蜘蛛池模板: 波多野结衣国产精品 | 久久精品一级 | 亚洲人成网站在线播放942一 | 波多野结衣一区二区三区在线观看 | 久久国| 激情插插插 | 免费看涩涩视频网站入口 | 亚洲国产成人精品一区91 | 小明台湾成人永久免费看看 | 成人青草亚洲国产 | a视频在线| 色综合久久88色综合天天提莫 | 免费v片在线观看 | 中文字幕欧美日韩久久 | 欧美黄色视屏 | 中文国产成人精品久久久 | 黄色a视频| 一级毛片视频免费观看 | 99热网站| 香蕉视频一区 | 国产综合一区二区 | 78m成人免费视频 | 99在线在线视频免费视频观看 | 欧美日韩精选 | 日本一区二区三区在线 观看网站 | 亚洲日本视频 | 欧美在线中文字幕高清的 | 国产福利午夜波多野结衣 | 一级a俄罗斯毛片免费 | 青草草在线视频 | 日韩在线中文字幕 | 欧美高大肥妇hdxxxx | 男人女人真曰批的视频动态 | 欧美色p| 黄色欧美视频 | 国产日韩欧美不卡www | 香蕉1024| 欧美成人鲁丝片在线观看 | 香港三级日本三级三级人妇99 | 欧美性xxx18一20 | 国产精品视频免费播放 |