Tag Archives: unit-тесты

Mock sql (sqlx) db on golang

I am using this library — https://pkg.go.dev/github.com/data-dog/go-sqlmock. That’s how you can use it for mocking db querying:

Mocking for unit-tests and e2e-tests in golang

Some patterns to test your golang app. Mocking an interface mockS3 := &mocks.S3API{} mockResultFn := func(input *s3.ListObjectsInput) *s3.ListObjectsOutput { output := &s3.ListObjectsOutput{} output.SetCommonPrefixes([]*s3.CommonPrefix{ &s3.CommonPrefix{ Prefix: aws.String(«2017-01-01»), }, }) return output } // NB: .Return(…) must return the same signature as the method being mocked. // In this case it’s (*s3.ListObjectsOutput, error). mockS3.On(«ListObjects», mock.MatchedBy(func(input *s3.ListObjectsInput) bool …

Read more

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: 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: …

Read more

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