2017年4月26日 星期三

[Tools] 單元測試利器 mock

[Tools] 單元測試利器 mock

目前接觸專案常常需要寫很多測試案例,基於分層測試再整合測試的原則,若是分層測試已經寫完,要再寫整合測試時,其實當中的很多測試都已經通過了,再重寫一次未免太過繁雜,故使用 mock 來協助處理一些可以被忽略的事宜。
以下就是目前常使用的 mock 利器:


mockito
http://site.mockito.org
GitHub
https://github.com/mockito/mockito
簡易說明:
https://goo.gl/b0uZGi
https://goo.gl/7YmE6v
https://goo.gl/qVvvli
https://goo.gl/mUEEzZ

PowerMock
https://github.com/powermock/powermock
教學
https://github.com/powermock/powermock/wiki/gettingstarted
PS. mock static,private field 或 method

EasyMock
http://easymock.org
教學
http://easymock.org/getting-started.html
GitHub
https://github.com/easymock/easymock

[簡易範例]

沒有留言 :

張貼留言