text stringlengths 0 2.35k |
|---|
**Natalie Pistunovich:** You even wrote that. |
**Bill Kennedy:** Wow... |
**Natalie Pistunovich:** It's on the Twitter blockchain. |
**Bill Kennedy:** I must have been willing to get lambasted on Twitter, because this stuff is like a religion to some people. So I get really nervous when I talked about -- even in training, I get nervous when I talk about testing, because some people are really just -- I don't know, they've got these really strong opi... |
Let me say this... I've learned from working in Go now for about a decade, and even learning how the Go team kind of develops. I've seen them go after this sort of prototype-driven approach. They start with a design document where they're really prototyping everything. Maybe it's on paper, I know they're trying it out ... |
\[08:00\] Then the idea for me is that I know, at least for myself, and with my teams, it can take a couple of days before we feel like we have an API that is checking every box in terms of what layer of code it exists in, what it can expose, what it can't expose... Even just today I had one of my engineers saying, "Bi... |
So if you're lucky, it just takes two days to get an API design where it checks every box. And so for me, at least, when I think about test-driven development, with the understanding that that means I've gotta write my tests first - I don't even have an API yet that everybody agrees on is designed the way it should be. |
Now, the moment we feel that the API is right, immediately I'm going to start writing some tests, because I can't do go build... And I can start testing that API. But for me, it's like putting the cart ahead of the horse. |
Now, I know that there are people who are very successful at doing this. I'm just not one of those people. I just know the way I work. So that tweet was more about the way that I work, and the way my teams work, and I feel like we get a lot of success with that approach. |
**Mat Ryer:** So how do you test the design? How do you test that API design? Is it literally on paper, and you're just thinking about it? |
**Bill Kennedy:** I'm doing two things. The first thing I'm trying to do is figure out, if this is in my business -- everything for me is a layering. So we've got three layers of code in all of our projects: we've got our application layer, business layer, and we have our foundation layer. And these layers have rules, ... |
So based on what layer you're in, we're already kind of thinking about what the API can do and what it can't do; what policies it can set, what policies it can't set. And so what we're really trying to do here is develop an API that eventually either has -- if it's a foundation layer API, it's going to be consumed by t... |
**Mat Ryer:** Yeah. |
**Bill Kennedy:** And this is why I get crazy when somebody wants to use these assert packages for tests, because it takes away from the experience of using the API as a user. that's your first opportunity to work with this API as a user. I just don't want to walk away from that. I want to experience even the pain of s... |
**Mat Ryer:** Yeah. But you are still using that API; just because you then make assertions about it... You're still using the API, aren't you? |
**Bill Kennedy:** For me, I don't have the visual connection to it, because I'm not seeing the 'if' there. I'm not seeing the fact that I might want to wrap the error inside the 'if' or I can't wrap the error inside 'if' and what is that gonna cause... There are things that you miss, I think, when you try to make the t... |
**Mat Ryer:** \[12:00\] Yeah, I think that is the benefit, really, of TDD, the one you've just described, is you get to be the first user. By the way, you know I've made Testify, don't you? You just talk about these assert packages, like "Oh, you know..." But you know full well I made Testify, mate... Well, yeah, so th... |
**Bill Kennedy:** Like stuttering and all the other little things that you wouldn't catch otherwise. I'm not writing a single function that has the word "test" in it until I feel like that API and my team feels like the API is where we want. I don't want to go back and redo test code because I didn't get the API right. |
**Mat Ryer:** But how do you know until you've used it? |
**Bill Kennedy:** Well, look, that's part of the code review process, We're looking at it. I might even, honestly, begin to integrate that into that upper layer. I might start to integrate it into the app layer, into the handlers that need to use it, and start to get that feel. And the moment we all feel like it's righ... |
**Chris James:** Yeah, I think what I find interesting about this is that what you've described is not so different from the way I work or the way my team works. And everyone on my team does TDD, Because software development is never as straightforward as you want it to be. It's a learning process, even for something t... |
So for me, an important thing about software development - this kind of goes beyond TDD - is this importance of high-quality and frequent feedback loops. We need to be able to hear about our design, we need to be able to hear about whether the behavior of our code is what we expect it to be. And for me, that's the stre... |
As you mentioned, what tests do is they also reflect your design back at you as well. So you can look at the design of your code, you can see it behaves how you'd and it's like a button press away; it's like Ctrl+F5, or whatever the magic incantation is on your IDE, to get that feedback that "Yeah, it works how I want ... |
So by starting by a test, it kind of centers you on a particular goal... Because I think another problem that I've encountered with people who don't do TDD -- I'm not saying this is true of everyone, but I've worked with a lot of inexperienced developers, and they think they understand a problem, and they start writing... |
\[16:17\] And I ask them, "How many times have you executed this code?" and it'd be like one or two times, when they can be bothered to wire it up into main.go, and then run the thing manually. And to me, the strength of TDD is it just gives you a very simple, repeatable process that gives you those feedback loops quic... |
But I think it's interesting that this kind of discussion is sort of framed as "I love TDD" or "I hate TDD", but really, actually we kind of have -- I mean, we're all software developers, and we all recognize that this is more difficult than people sort of give it credit for. We need to be able to learn quickly. So I f... |
**Bill Kennedy:** I think it comes down to the order of things. I'm not writing tests first. For me, TDD is always - and I could be wrong, but when I first heard about TDD, it was always write tests first. And that order that I gave you, Natalie - I don't remember off the top my head, but can you read that order again,... |
**Natalie Pistunovich:** Prototype, solidify, refactor, test, minimize, reduce and simplify. |
**Bill Kennedy:** Alright, so I have Test fourth there, which is kind of what I said, right? We need a package that does this. Let's design the API. Let's see how it feels. Do we feel like it checks every box? Good; we like it. Now let's write the tests before we do a go build, so we know that that API is behaving that... |
**Mat Ryer:** I think it's write tests first. Chris? |
**Chris James:** But I would add it's write test first. This is the interesting thing about TDD, is that there's unfortunately a lot of misrepresentations from what Kent Beck & co write. I think a lot of people seem to be under the impression that you get given this project of "Let's rewrite Twitter." And okay, I'm goi... |
So for me, that is a really common misconception, and that's why when people say things like "I don't have time to write tests first", and I'm kind of like "Mate, it takes like five minutes, if that." It shouldn't feel like a big blocker to you achieving work. The opposite, in fact. Once you get proficient at TDD, and ... |
**Bill Kennedy:** Yeah, it's mind blowing to me, Chris; mind blowing. I cannot -- I'm telling you right now, the thought of me writing a test first, for an API that doesn't exist yet, because I haven't really figured out what I need it to do is mind blowing. |
**Mat Ryer:** But when you think about the design of that API, Bill - like, it's going to be used by somebody writing code; they're going to be calling functions, and using types in that package, and things. That's the bit I don't get. Because for me, first of all, I should say, I have had the case before where I've ov... |
\[20:25\] So Chris's point I think is quite good, but you write a bit of a test first, and then you do a bit over here, and you sort of do them at the same time. But driven by the test means you automatically get better coverage, because you immediately -- well, in my experience, the test coverage is always high, kind ... |
**Bill Kennedy:** So just recently, I had to write an API to access some service out there; there's authentication bits to it, there's HTTP calls I have to make, there's data coming back... I wrote 30 lines of code to start; happy path. I put my programming hat on, right? Find the 30 lines of code that make at least pa... |
**Chris James:** So I think a useful thinking tool when I'm coaching people TDD is I ask them to sort of ask themselves, "Pretend this code already existed as an open source package. What would you want to see?" And it gets you to forget about the implementation details. When you're designing packages in Go, the good o... |
But what you need to be doing when you're in this mindset is have this positive attitude towards it, and go "What would be the best package design that I as a user could put in front of myself?" and then encode that as a test. And you immediately document it to yourself; you sort of say, "Okay, so if I do this right, I... |
Because how many tests have we all seen where it's like there's a load of messy implementation details and things that's really difficult to read... And worse still, difficult to maintain, because then when you change an implementation detail, you're suddenly like "Oh, my goodness... Ten tests are now failing because I... |
**Mat Ryer:** I quite like those errors that you get, actually. Like, when you write a test for something that just completely doesn't exist, you get compiler errors, but you get one error at a time, and it's almost like a to-do list; it tells you what to do. And then once you've got past all your compiler errors, you ... |
\[24:08\] And the classic case of -- if you take red/green testing, this idea that it's important to see a test fail first...Or if you write a test, and it always passes, and it's always passed, how do you know you're really saying anything about the service, or anything? So I really want to see it fail, so I know it's... |
**Bill Kennedy:** The majority of packages I write are not single-module packages that are going to be in somebody's vendor folder. They are for these big projects, where we've got four people working on this thing, and now the app layer needs support for being able to order things from the database. So now I've got to... |
And so for those packages, the majority the packages I write, I really need to be thinking about the design as it relates to how its integrated into this project; not as a vendor package. So again, my brain says, "If I'm writing tests first, I'm not leveraging my time enough." Because I really don't know how it fits be... |
**Break:** \[27:02\] |
**Natalie Pistunovich:** Chris, I have a question for you. You said that it's important for you to separate the responsibilities, and decouple, and make sure that each part is individual, and that way it's simple, and you know that when you're asking, "What is this doing?", "This is doing this one thing." "What is this... |
**Chris James:** I tend to favor top-down development, because it's the least risky way of working, in my view. I've seen a lot of kind of bottom-up efforts where people are making these kind of beautiful-looking packages, that have corresponding beautiful test suites... But then when you try and integrate them togethe... |
So I generally prefer a top-down approach, and I would definitely plug Steve Freeman and Nat Pryce's book "Growing object-oriented software, guided by tests." And I know some people in the Go community are a bit allergic to OO, and it's a Java book as well... But I promise you it's a valuable book, because it kind of t... |
So you have your \[unintelligible 00:30:40.15\] acceptance test, and then you just start writing some code. And then again, like the kind TDD approach in itself, at first you're just trying to make the tests pass. You're not worrying too much about package design. Honestly, when I do it, most of the time I'm making it ... |
**Mat Ryer:** Are your acceptance tests integration tests then, essentially like end-to-end tests? |
**Chris James:** Yeah, the naming around all this stuff is incredibly confusing. For me, an integration test is something that takes two units, or two or more units and checks that they integrate and do something together. For me, an acceptance test is something that tests the system as a black box. So if you're making... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.