JsUnit
javascript 的 Unit Test 工具。
2007年1月18日 星期四
2006年12月25日 星期一
測試預期的 Exception 行為
當某個方法我們預期會丟出 Exception 時,
可利用 fail 這個述詞來測試。
如以下的 JUnit 語法:
可利用 fail 這個述詞來測試。
如以下的 JUnit 語法:
public void testGetUserException() {
User u = null;
try {
u = UserFetcher.getUser("ThisUserIdDoesNotExist");
fail("Should have gotten NoSuchUserException - used a bad user ID");
} catch (NoSuchUserException expected) {
; // Expected - intentional
}
}
訂閱:
文章 (Atom)