Tag Archives: unit-тесты
A way to test http client in go
A couple of ways are described here — http://hassansin.github.io/Unit-Testing-http-client-in-Go The way I liked is the following one:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
func Test_Mine(t *testing.T) { ... client := httpClientWithRoundTripper(http.StatusOK, "OK") ... } type roundTripFunc func(req *http.Request) *http.Response func (f roundTripFunc) RoundTrip(req *http.Request) (*http.Response, error) { return f(req), nil } func httpClientWithRoundTripper(statusCode int, response string) *http.Client { return &http.Client{ Transport: roundTripFunc(func(req *http.Request) *http.Response { return &http.Response{ StatusCode: statusCode, Body: ioutil.NopCloser(bytes.NewBufferString(response)), } }), } } |
Golang: testing http and grpc servers
HTTP server is quite easy to test — here is a nice video about it:
Tape: тестовый фреймворк без б
https://github.com/substack/tape Здесь рассказывают, чем он лучше Моки, Жасмина и прочих: https://medium.com/javascript-scene/why-i-use-tape-instead-of-mocha-so-should-you-6aa105d8eaf4 Если коротко — прост в настройке, нет всяких хитрых сложных мокеров, вместо before/afterEach православные setUp/tearDown.
unit-тестирование AngularJS
http://www.yearofmoo.com/2013/01/full-spectrum-testing-with-angularjs-and-testacular.html — эту статью я уже упоминал; теория тестирования AngularJS. http://docs.angularjs.org/guide/dev_guide.unit-testing — небольшая и не слишком полезная официальная документация. http://karma-runner.github.io/0.8/index.html — инструмент для запуски автоматических тестов (как правильно подгружать внешние шаблоны). Примеры: https://github.com/vojtajina/ng-directive-testing https://github.com/angular/angular-seed https://github.com/IgorMinar/foodme/tree/master/test