顯示具有 單元測試 標籤的文章。 顯示所有文章
顯示具有 單元測試 標籤的文章。 顯示所有文章

2007年1月18日 星期四

JavaScript 實務:使用 JsUnit 作單元測試

JsUnit
javascript 的 Unit Test 工具。

2006年12月25日 星期一

測試預期的 Exception 行為

當某個方法我們預期會丟出 Exception 時,
可利用 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
}
}