參考文章 http://blog.lvscar.info/post/...html
在編寫前端測試代碼的過程當中, 幾乎全部的測試框架都提供了根據功能、模塊(module ,spec
)來切分測試用例的設計, 因爲測試代碼簡單,直接,直接反應API
的特色,咱們編寫測試代碼的體驗很大程度上取決於所選用的斷言庫, 如下是我對目前幾款主流斷言庫的選型分析筆記:前端
C-style TDD
斷言庫git
由TJ Holowaychuk 發起github
目前Github上的有 : 131 star 14 forkweb
assert('tobi' == user.name) assert('number' == typeof user.age)
BDD
風格斷言庫框架
一樣由 TJ Holowaychuk 發起post
目前Github上的數據: 384 Star , 200 fork ( TJ放棄維護後由新開發者接手)測試
foo.should.be() bar.should.have() foo.should.bot.be()
追求極簡的 BDD
風格斷言庫prototype
基於 should.js
簡化插件
目前Github上的數據: 926 star 135 fork
expect(foo).to.be() expect(foo).to.eql() expect(foo).to.be.a() expect(foo).not.to.be.an()
BDD/TDD
雙模 ,同時支持 should / expect / assert
三種風格的斷言庫
強大插件機制
chai-webdriver
Github上的數據1559 star 150 fork
should style: foo.should.be.a() expect style: expect(foo).to.be.a() // 近Jasmine風格 assert style: assert.equal(foo, 'bar')
Jasmine.js 測試框架中的斷言庫十分相似 Chai expect
和 expect.js
( Jasmine歷史比前二者悠久).
assert
風格最保守 , should
風格須要修改prototype
最爲激進。
不考慮Node
環境的話,Jasmine.js
是好選擇
我目前傾向於 Mocha + Chai
的測試方案