天天看點

Angular jasmine單元測試架構spec的運作時資料結構

以我單元測試裡這段代碼為例:

Angular jasmine單元測試架構spec的運作時資料結構

通過describe函數建立一個suite,即spec的集合:

Angular jasmine單元測試架構spec的運作時資料結構

真正的spec由函數it建立:其中expectable是human readable的字元串描述資訊,描述該spec具體要測試哪些東西,assertion就是具體的包含單元測試的代碼。

Angular jasmine單元測試架構spec的運作時資料結構

spec内部的expect方法調用:調用env.expect:

Angular jasmine單元測試架構spec的運作時資料結構

使用spec的expectationFactory建立一個expectation: