分類: Unit Testing

Python test framework: nose 介紹 – Part 2

寫 test case 時我們通常會在每個測試案例執行前先做初始值設定(setup),與測試案例結束後的設定(teardown),在 nose 這套 test framework 也包含了此功能,與 unittest 的 setup 與 teardown 意思一樣 (可參考 Unit Test Framework – JUnit 3 或 Unit Test Framework – JUnit 4)。

繼續閱讀 “Python test framework: nose 介紹 – Part 2″

Python test framework: nose 介紹 – Part 1

Python 的標準函式庫已經提供了兩個單元測試模組,分別為 doctest 與 unittest,但更值得注目的是第三方的 nose 模組。在 nose 的說明文件中,標題很清楚的寫到「nose extends unittest to make testing easier.」,它的功能比 unittest 模組還要完整。

繼續閱讀 “Python test framework: nose 介紹 – Part 1″

一些提升 Assertion 可讀性的方式

在使用 JUnit 時,我習慣使用一些方式以提升 Assertion 的可讀性:

1. 將預期的結果放在前面,以方便對照(也符合 JUnit Assert 的說明規範)
2. 在擁有多個 Assertions 的測試,選用有 message 參數的 Assertion,以方便在出現錯誤時印出我們給予的資訊,輔助判斷情況和位置
3. 如果要比物件的話,盡量善用比對其種類的 Assertion,盡量不要自己比過才 Assert,因為直接比對的話會比較貼近原始資料,若比對不符所印出來的資訊也比較完整
繼續閱讀 “一些提升 Assertion 可讀性的方式"