亚洲好骚综合-亚洲黄色录像-亚洲黄色网址-亚洲黄色网址大全-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
主站蜘蛛池模板: 日韩51 | 国产aⅴ一区二区 | 国产成人无精品久久久 | 国产精品人成在线播放新网站 | 国产 第1页 | 国产日韩欧美精品在线 | 永久在线观看www免费视频 | 亚洲精品xxxx | www.伦理片| 最近中文字幕免费国语 | 久久精品最新免费国产成人 | 亚洲五月激情综合图片区 | 黄色一级片中国 | 天堂在线资源网 | 久草手机在线播放 | 午夜一级毛片 | 亚洲一区2区三区4区5区 | 先锋影音国产精品 | 国产成人咱精品视频免费网站 | 国产欧美精品区一区二区三区 | 亚欧在线 | 狠狠色狠狠色综合日日小蛇 | 免费播放欧美一级特黄 | 特黄特级高清免费视频毛片 | 久久精品香蕉视频 | 草草影院地址 | 亚洲色图综合网 | 中文字幕22页 | 日韩精品观看 | 天堂中文资源在线8 | 视频二区国产 | 精品哟哟哟国产在线观看不卡 | 中国特级黄色片 | 久久黄色大片 | 在线免费黄视频 | 国产精品xxx| 最近中文字幕在线看免费视频 | 欧美激情一区二区亚洲专区 | 亚洲专区欧美 | 一级毛片免费一级直接观看 | 免费看片亚洲 |