text stringlengths 0 2.35k |
|---|
**Mat Ryer:** Okay. |
**Chris James:** \[32:06\] Integration tests are more within the system for me. |
**Mat Ryer:** Okay. So an end-to-end test maybe we could call that. |
**Chris James:** Yeah. |
**Mat Ryer:** Yeah. So it's funny, because that is how I do it... So I have a thing that we're building, and it has a frontend, and it has a backend with an API. And the API is like -- when we run this test suite, it literally spins up the database, it spins up the whole thing, and accesses it like the client is going ... |
We actually have an API client as well, which it uses. So we're also kind of testing that at the same time as well. So this is like really getting as close as it can to what the browser is going to do. And then I'll be able to write then in quite a clear way what I expect. Like, I'm going to do one thing, and then I'm ... |
And then yeah, you go about implementing it, making that test pass... And you sort of -- because of that approach, I know that that new feature works as I expect, whatever else is going on. And I can get -- actually, sometimes we'll skip unit testing in some places, because that's just such a kind of reliable thing tha... |
**Bill Kennedy:** I'm always worried about guessing. I don't want to guess. Let me give you an example, because you mentioned frontend... I have a person that works for me, he's a frontend dev; we were working on something, and I started doing a code review... And it was all JavaScript Node, so I was really losing my m... |
**Mat Ryer:** Yeah, great. |
**Bill Kennedy:** I said, "You tell me what you need, and I will do my best to make that API work for you." And then I'll work from the business layer first, so I can feed that, and then I'll work at, say, the data layer. But it's so sad, because a lot of the APIs that I had felt right to me, but were not frontend cons... |
**Mat Ryer:** Yeah, but I think you just did TDD, really; you built the terminal... It's not tests as code, but it is like, you are testing it; like, you run the thing, see if it works, and then make changes to it that way. That feedback loop is what you needed from that process. |
**Bill Kennedy:** \[36:07\] For mocking out the handlers as a test-driven thing? I mean, I was asking the frontend to do that, so they could drive my design, because I don't want them to be -- you know how horrible it is when you have an API that's not even doing error handling consistently? The amount of extra code a ... |
**Natalie Pistunovich:** I guess the big difference here is that somebody else is testing for you. |
**Bill Kennedy:** I say this in class - we write APIs all day, so you can either make somebody's life amazing, or miserable. And we've all not wanted to go to work the next day, because we had to work with an API that was just... Dude, I had a JSON API return XML on me once. |
**Mat Ryer:** \[laughs\] |
**Bill Kennedy:** And then I had to deal with that. |
**Mat Ryer:** Inside JSON? Or just pure XML. |
**Bill Kennedy:** Pure XML, not inside JSON. Apparently, they were fronting an XML service instead of rewriting it; they were transcribing XML, and I found a call that bypassed the trans-- \[laughs\] But you understand what I'm saying... Consumer is everything. And I call them the user. The user is everything. And if y... |
**Mat Ryer:** Fair enough. |
**Bill Kennedy:** I never do it right. |
**Mat Ryer:** Yeah, I think that's fair. I think that totally makes sense. I think TDD is about being obsessed with the user; you become the user. And to be honest, in the case I talk about, it's possible for me, from just starting at the API, it would be possible for me to build a horrible API, i.e. you make this call... |
But I wonder, Bill, if -- and I don't know the answer to this, but I do wonder if the approach changes what we end up with much, or if we sort of end up in the same place, regardless of process. Because when you talk about things being like in your big system, where there's lots of moving pieces, and you have to think ... |
**Bill Kennedy:** It's about, for me, trying to minimize the amount of guessing you're doing, and prototyping does that. The more you can prototype and solidify something, then the less guess you're going to deliver. So I'm curious, Mat, since you do a lot of frontend stuff, if you're not the one working on the fronten... |
**Mat Ryer:** Yeah, so that is interesting. I love that idea. One thing we did in the past place was we would collaborate on that JSON API, and we'd have a .json file, and we'd just serve that from the backend. So the frontend is unblocked, because they're getting at least the test data. A bit like how you said, just h... |
So yes, I think you're right, the frontend is really kind of paramount, because that's where the actual end users are going to be touching something. So I put more importance in that. So if a frontend needs data in a particular way, I think that outweighs what else might be considered there... |
**Bill Kennedy:** \[39:57\] Yeah. So I don't want to guess, and you are going to have some level of guessing. It's impossible until you actually finish whatever that integration is. But I want to minimize that. And I just feel like, personally, that if I'm starting with writing tests - again, because I'm not just writi... |
I have a person on my team that likes to start the business layer. Doesn't want to even look at like -- a data store is a complete abstraction to them, right? So they just want to completely start in the middle of the business layer, and get a feel for those APIs first, before we do anything. There's lots of ways to su... |
**Mat Ryer:** I think that's going to end up being where we land on this, honestly... But yeah, so what we'd do with those JSON files in the past place - they would be the tests for the backend API. So it gets served to the frontend for them to code against, and it becomes the same file as the test. So we call the API ... |
**Bill Kennedy:** But here's the cool part with letting my Node developers write handlers... Because they learned how to do that in like 15 minutes. They're designing, at some level, the application-level models. And I'm making them define -- and I show them how to write a literal struct. But they're also defining the ... |
**Mat Ryer:** Yeah, I love that. I mean, that is literally how I like to work as well. So I think I'm with you there. While you're implementing it, do you then ever say, "Oh, hang on... I've just learned something. I can't give you it like that. It's going to have to be like this"? Do you have that handshake? Or will y... |
**Bill Kennedy:** I try to keep the application model exactly the way they want. And then at the business layer we define our own models that are going to work better for \[unintelligible 00:42:49.11\] Right? But there are times, obviously, where we've gotta negotiate... Time is a great example. Time is a nightmare. Ho... |
**Natalie Pistunovich:** I also want to answer your question, Mat, although it was for Bill... |
**Mat Ryer:** Please do, Natalie. |
**Natalie Pistunovich:** ...if this is the same goal, or is this - you end up in different places, doing the two different methods... Because recently, I had a project where it was a very new, and it was not TDD at all; it was very much -- not with the frontend, but actually with two microservices. And it was one team ... |
**Mat Ryer:** Yeah, I think you might not end up in the same place. But also, that I quite like also, having somebody else write the tests. If you're pairing, it's quite nice to have - one person will write a bit of a test, and the other person then switches and does the implementation. That works quite nicely as a way... |
And I feel like often whenever someone on Twitter, or whichever platform is now still going, by the time this goes out on Thursday... I feel like when there's a strong opinion like this, and there's big disagreement, what we find out if we dig in deeper is we're actually doing different things, or the scenario is subtl... |
**Break:** \[45:21\] |
**Bill Kennedy:** So I want to answer to something Dylan's asking on Slack, and I really would love Chris's opinion on this, too... Because I have opinions on this. Dylan's asking two things. He's asking about "Tests must be fast, and spinning up a Postgres database in Docker." Let me just talk to that. I do that. I fe... |
But the other thing is the big one, where it's this idea that if your test hits a database, it's not allowed to be a unit. So let me just tell you what I think a unit test is, and then I'd love to get Chris's opinion. See, what I love about Go is it's already defined what a unit of code is. We don't build monolithic co... |
**Chris James:** I wish I could bring in some controversy, but I basically completely agree. I think there's been a big misrepresentation in tech about what a unit test is... Or it could only be a particular function, or whatever. I wouldn't describe it as a unit test; to me, this is an integration test. But that disti... |
Yes, I'm afraid to say, I basically completely agree. I think mocking the database is really clunky and difficult to do, and you still don't really have particularly useful tests, because you can prove that like your SQL string equals select star from users, but does that do what you need it to do? I don't know... It j... |
**Mat Ryer:** So it's really like -- maybe we could talk about things that your tests should give you. I think the feedback loop thing is very important. By the way, you can just spin up a database and keep it running as part of your dev environment too, and just clear it out every time, rather than having to spin up t... |
\[49:59\] But yeah, so that is a question people should ask, because there's a lot of language -- I don't know what people mean when they say an integration test, honestly... I don't know what they mean. I'd have to find out, I'd have to ask them more questions. So what do you get from your tests? Is it really telling ... |
**Bill Kennedy:** Yeah, I think the useful thing to look at here is the test pyramid, which describes different kinds of tests in the shape of a pyramid, funnily enough. So at the top of a pyramid you have your end-to-end tests, your acceptance tests... And the idea is that you should only have a few of those comparati... |
Integration tests - you're getting a few more of those; they're proving that two lumps of code, whether it be two packages, or a package and a Postgres database, whether they work together... Again, they're faster than your end-to-end tests, they give you better quality feedback, but again, because they're two differen... |
And then finally, you have unit tests, which are what you're describing, Mat; typically, when they fail, you get a very precise reason as to why they fail, and they also give you really fast feedback loops. These are the ones that really helped you refactor, because you want to be able to do refactoring frequently, and... |
And you should have loads of unit tests, to a point. You can get to a point where you have perhaps too many tests that are kind of coupling themselves as stuff you don't need, and I'm sure we've all been in projects where there are tests that are impeding our ability to change a system. You get to a point where you're ... |
**Bill Kennedy:** I have a question for everybody here... NASA did a study and they said roughly every 20 lines of code you write, there's a bug in your code, whether you like it or not. Now, this was off of their codebases that are written in C, so maybe we get some better numbers out of Go. |
**Mat Ryer:** Who's this NASA? |
**Chris James:** That's boring, ain't it? |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.