Mocha 運行在nodejs和瀏覽器下的JavaScript的單元測試框架。
- 用於寫測試用例的宏,屬性或者函數
- 斷定庫, 用於測試是否可以通過
- 輔助庫,如hook庫(測試前後調用某些函數或者方法),異常檢查(某些函數在某些參數的情況下拋出異常), 輸入組合(支持多排列的參數輸入組合)等。
- 支持IDE的集成
Hooks(鉤子)
before(function() {
// runs before all tests in this block
// 在執行所有的測試用例前 函數會被調用一次
});
after(function() {
// runs after all tests in this block
// 在執行完所有的測試用例後 函數會被調用一次
});
beforeEach(function() {
// runs before each test in this block
// 在執行每個測試用例前 函數會被調用一次
});
afterEach(function() {
// runs after each test in this block
// 在執行每個測試用例後 函數會被調用一次
});