Category Archives: Testing
Load testing tools
https://yandex.ru/dev/tank/ [Tool | Free] https://jmeter.apache.org/ [Tool | Free] http://tsung.erlang-projects.org/ [Tool | Free] https://gatling.io/ [Tool | Free/$] https://k6.io/ [Tool | Free/SaaS] https://locust.io/ [Tool | Free] https://loader.io/ [SaaS | Free/$] https://artillery.io [Tool | Free/$] https://github.com/wg/wrk [Tool | Free]
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:
E2E tests in go
I tried it via ginkgo and gomega. It has Agouti with WebDriver support out of the box, but I didn’t use it as we have grpc API. That’s the example (table tests):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
var _ = Describe("GetRoute", func() { var ( srClient sr.Client srErr error ) JustBeforeEach(func() { srClient, srErr = GetClient() }) DescribeTable("positive cases", func(fromGeoPointID, toGeoPointID int, expectedUID string, expectedCostGreaterThan float64) { Expect(srErr).NotTo(HaveOccurred()) Expect(srClient).NotTo(BeNil()) response, err := srClient.GetRoute(context.TODO(), &sr.GetRouteRequest{ FromGeoPointId: int64(fromGeoPointID), ToGeoPointId: int64(toGeoPointID), Quantity: 1, Volume: 1, Weight: 1, }) Expect(err).To(Succeed()) Expect(response).NotTo(BeNil()) Expect(response.RouteCost).NotTo(BeNil()) Expect(response.RouteCost.RouteUid).To(HaveSuffix(expectedUID)) Expect(response.RouteCost.GetCost()).To(BeNumerically(">", expectedCostGreaterThan)) }, Entry("from(geo=3)->to(geo=2)", 3, 2, "-3-2", float64(10)), ) |
Mocking for testing go code
If you’re testing go code and have a huge API you have to mock, you have two options: make your dummy struct with embedded interface and implement only methods you need, or use your own interface that has only methods you need (and change your code to use that). For instance, I had amazon’s s3 …
BDD Framework For Golang
There is a good one: https://github.com/onsi/ginkgo It prefers to use http://onsi.github.io/gomega/ as a matcher.
Testing react’s dom with jest and enzyme
Install it like this:
1 |
yarn add enzyme enzyme-adapter-react-16 --registry="https://registry.npmjs.org" |
Regression testing of react app with jest
Example is here — https://facebook.github.io/jest/docs/en/tutorial-react.html. The main idea is this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
// Link.react.test.js import React from 'react'; import Link from '../Link.react'; import renderer from 'react-test-renderer'; test('Link changes the class when hovered', () => { const component = renderer.create( <Link page="http://www.facebook.com">Facebook</Link>, ); let tree = component.toJSON(); expect(tree).toMatchSnapshot(); // manually trigger the callback tree.props.onMouseEnter(); // re-rendering tree = component.toJSON(); expect(tree).toMatchSnapshot(); // manually trigger the callback tree.props.onMouseLeave(); // re-rendering tree = component.toJSON(); expect(tree).toMatchSnapshot(); }); |
Javascript mocking frameworks
Classical one — http://sinonjs.org/. TestDouble — https://github.com/testdouble/testdouble.js/blob/master/README.md There is a good video on using TestDouble from it’s creator: https://www.youtube.com/watch?v=nH8EnmdEBj4
HTTP stress testing tools
Старый добрый ab, из минусов — только http 1.0, задействует только одно ядро. JMeter wrk hey (бывший boom) — написан на go. Yandex.Tank Siege