Sitemap
androvideo

Andro Video

Test Gin with httpexpect

--

測試 http 一向是個浩大的工程,Go 有一個原生模組 net/http/httptest 正是為此存在,然而 httptest 並不是一個“易用”的框架,從官網文件的使用案例就能看出這個問題

因此我們需要一個更加高階的測試框架幫助我們組織測試的邏輯

這個框架就是 httpexpect

Get dannypsnl_androvideo’s stories in your inbox

Join Medium for free to get updates from this writer.

因為公司用 Gin,所以示範的程式就用 Gin 寫,首先建立一個簡單的伺服器,它在 ”/” 回傳字串 “Home”

接著是測試的部份

httpexpect 巧妙的利用串接函數呼叫組成了更有意義的測試案例

--

--