Hello, everyone. My name is Valentin Kononov, and today my lightning talk is about end-to-end tests for API. How I did it. How it saved my nerves and hours and so on so forth.
But still just a little bit about myself. So, I am a developer, mostly working with TypeScript and JavaScript these days, so with Node.js, and especially with the backend. And on one of my last projects, we had a backend written in NestJS, and we struggled a lot with testing it, especially when we need to change some functionality. That's how we tried to eventually move to end-to-end test, and here is what my talk about.
At the moment, I'm working at a Unity company, and it's all about fun and games and stuff, but I am working in the advertisement department, so we have a lot of services and both frontend and backends, and of course, we need to test them carefully.
Straight to the point, we don't have too much time. When we talk about API testing, what do we usually mean? First of all, we need to test the data flow, so how the data flows through our services, what are DB queries, so what input, output and data transformers. And in most cases, we just need to test if crude operations work fine and the syndication work fine and all the endpoints are correct, and what we usually do to achieve that. Of course, in most cases, we have integration tests.
And how does it work? Integration tests usually test the whole module, like the whole service, but the service is not something which is present by itself, it's something which communicates with other modules like a database or data repository or some syndication model, something else. So that's why to test it, we need to mock some dependencies. And when we did that and the test is working fine, what do we do next? We update the code, we make some new features. And what do we need to do next? We need to update the mock dependencies, so that the test keeps working. And what else? Yes, we need to update mock dependencies once again, and again, and again, and again.
So I really faced it. We had a really big, important, super mega-critical test about some export process. And every time we changed a minor thing in the export code, we needed to completely rewrite the whole test. That was bad. So, how usually the integration test could look like with all the mocks? So it's actually a huge pile of different kinds of mocking functions, like you see in the slides. Sometimes we mock the whole module, sometimes we mock just one function. And of course, when something is changed in the function, especially in the last example here, the update function was changed, and its output was changed. Even the format of output, like it was an object, became just one simple number. So, we needed to update the mock. And that actually sucked because we spent a lot of time just for supporting the tests. But it should be vice versa, so tests should save all the time for the development. So is there any alternatives of how we can proceed so that the whole process would be easier for us as developers? Basically, my recipe for that was end-to-end tests.
Comments