Golang test
(1.)单元测试性能测试
https://github.com/guyan0319/golang_development_notes/blob/master/zh/1.9.md
(2.)gotests使用
https://github.com/cweill/gotests
(3.)Goland插件
https://www.jetbrains.com/help/go/creating-run-debug-configuration-for-tests.html#test-configuration-for-a-package
(4.) echo框架测试
import (
"net/http"
"net/http/httptest"
"strings"
"testing"
"github.com/labstack/echo"
"github.com/stretchr/testify/assert"
)
var userJSON = `{"name":"Jhon Doe","address":"High St."}`
func TestModel(t *testing.T) {
url := "/new_house"
e := echo.New()
req, err := http.NewRequest(http.MethodPost, url, strings.NewReader(userJSON))
req.Header.Set("Content-Type", "application/json")
if err != nil {
t.Errorf("The request could not be created because of: %v", err)
}
rec := httptest.NewRecorder()
c := e.NewContext(req, rec)
// c.SetPath("/new_house")
// c.JSON(http.StatusOK, Devices{"Jhon Doe", "Middle Way"})
res := rec.Result()
defer res.Body.Close()
if assert.NoError(t, newHouse(c)) {
assert.Equal(t, http.StatusOK, rec.Code)
assert.Equal(t, "["+userJSON+"]", rec.Body.String())
}
}
https://echo.labstack.com/guide/testing
https://github.com/labstack/echo/blob/master/echo_test.go
【励志篇】:
古之成大事掌大学问者,不惟有超世之才,亦必有坚韧不拔之志。