Let's say that you are the chief testing officer or the CTO and I'm your developer, and I'm working traditionally. Well, I'm writing unit tests, a lot of unit tests. Then after three weeks, when I have the version working with 100% test coverage, hoo-hoo, then me and the QA person starts writing some integration tests and then some end-to-end testing, then manual testing my version and put in production.
Now we have a meeting and we do our planning for 2021. What exactly, and Oren, let's start with you, what exactly should I change in this approach for the next year? So when you start planning, I think first of all you need to understand what you have and how do you want to go. We all know the pyramid, right, and we all say this is the amount of tests that we have, unit tested, unit tests is not enough, and deciding on over there, everyone tries to reach the hundred percent test coverage. Code coverage is really hard, it's really hard to get to 100% code coverage and sometimes it's not worth it.
So you have those different layers and you need to decide how to start. And sometimes, by the way, if you don't have anything, sometimes it's even nicer to go actually against the tradition and actually start from the top. End-to-end testing and the integration tests give you high coverage very, very fast. And they give you a lot of confidence, as you said, close to production to understand, or you can even test in production to understand what you got. The other thing that you need to make sure is that you don't neglect those other layers and you need to make sure that you keep investing in them because they give you the feedback faster. So the end-to-end are super critical, they give you high confidence, and high coverage in seconds, where they usually, the challenge over there is what Kent said, and I totally agree, is the trust.
You need to trust your tests. If you have tests that are running and you don't trust them, I don't want them. I don't, I prefer 10 tests, they give you 20% coverage and I trust it, then 100% that it's flaky, and when the CI would go, I would say, oh, it failed again, I don't know why. And then what happens is people take tests out, and they say, I don't trust it, let's take it out because I want to release, or they're starting this thing called rerun, you know what, let's run it again, and again, and again, and again, let's rerun it, until everything passes. And that, of course, it covers a lot of bugs that you don't catch because of those flakiness, you might have a real bug, people think that bugs are only deterministic bugs, that you say, hey, I caught this, and this will always reproduce, the most challenging bugs are the one that don't reproduce all the time, when you have that one out of 10, it's gonna happen, and you can ignore that. And I keep telling people, if you had someone, a robbery, you can't say, the robbery is not gonna go up in the same place again, you need to make sure, how do I find the person that did this, how do I find it, and that means how they had all the information, and that brings us to the root cause analysis, understanding, you need to invest in the fact that you'll know when something does break, what happened, do I get, is it, we started with the screenshot, then, you know, the dom, I wanna see the dom, the network request, the console logs, I want to have all the information I need, so that when something does happen, I know I can pinpoint and say, okay, this is it, and of course, the more you go up the dom, it's harder to say, to pinpoint, and as you go more to the, more even toward the unit tests, you can say, oh, here's the function that, the method that went wrong, this is the state. So here gives us, up to here, we see a very, we have a lot of coverage, slow response, that means it's harder running on every commit, and going down, making sure that we have the amount of tests in each, in each part, to know exactly as fast as possible what went wrong.
Yeah, yeah, that makes sense, the wider your tests are, then you need more to invest in setups that prevent flakiness and, yeah, makes tons of sense. Jason, many of your work is related to flakiness, so I'm curious about your overall thought, but also specifically to this, flakiness in integration tests.
Yeah, flakiness is a big problem, but it's also kind of a fascinating field as well, something I'm sort of weirdly interested in. I can sort of say at Spotify, we had kind of a large flakiness problem. That's kind of how I got introduced into working and testing to begin with. The library that I wrote, JestJUnit, the entire reason I wrote it was because I was working on the Spotify desktop client at the time, and we were trying to tackle test flakiness, trying to reduce it significantly. And so the first part in doing that is just basically knowing what tests have run, which one failed, how fast are they, et cetera, et cetera, putting them in a database and sort of trending these things over time. This is kind of the fundamental starting point for just understanding what is flaky and then how are you going to address this. So it's a fascinating field. There's probably tons I could talk about, way more than this conference.
Comments