9 ms·
I gained a new appreciation for Test Driven Development
- invalidname 4y agoI find it's usually more pain than it's worth: https://dev.to/codenameone/why-i-dont-do-tdd-1j71 https://dev.to/codenameone/why-i-dont-do-tdd-1j71
- camjohnson26 4y agoI have a feeling TDD proponents work in very different code bases than I do, the point in this article is spot on that TDD emphasizes nice to have unit tests over the much trickier but more bug prone integration tests. For frontend dev the surface area of things that can go wrong is much higher than say in programming an api, so just writing the tests for a lot of changes seem much more difficult than writing the code itself, since you won’t know what can go wrong until you build it. A lot of frontend programming is throwing something on the DOM and then trying to understand the weird ways it went wrong, like a scroll bar width is slightly different in every browser, or the line height for a text input behaves unexpectedly if you change a font. I have no idea how you would build these features with TDD. Seems like the more formal your codebase the more useful it is.
- jonstewart 4y agoHaving some ADD tendencies, I love TDD for helping me focus and get started—without it I just daydream about software rather than write the software. Once I get going then I’m okay (though I still use TDD) but TDD and pair programming are both great for me, to get me started. I also have two young kids and can absolutely relate to the author.
- tccole 4y agoYeah, I have diagnosed ADHD and I struggle staying focused and on task (and it occasionally gets me in trouble). But TDD gave me a framework to get things done and focused in a doable fashion.
- bcassedy 4y agoFor me switching between code and tests is a context switch. TDD approaches that I'm familiar with encourage frequent swapping between them which really drains my productivity. It's much easier for me start something and hyperfocus than it is to swap back and forth.
- antifa 4y ago> For me switching between code and tests is a context switch Not as big as the context switch that is between code and browsing the GUI of your app.
- tccole 4y agoI think the true struggle of ADHD is that you’re in fact constantly context switching. There’s the great theory that being adhd is an evolutionary advantage because it made hunting easier.
- 7speter 4y agoIt seems quite overwhelming and daunting to me
- papito 4y agoI would say overwhelming and daunting is not knowing why your software becomes fragile and low quality without tests. TDD gives you a sense of control. You know that you are done once your tests (read: documented requirements) pass. And yes, I realize not doing TDD is not the same as not doing tests at all, but writing tests post-fact is just an excuse to wiggle out of writing them. "It worked when I coded it!"
- wpietri 4y agoI think it's harder to set up a project initially for it. And converting a brownfield project to tests is a bear. But once it's working, it's the opposite of overwhelming. The red-green-refactor cycle of TDD lets you take work in very small chunks. And because you get great test coverage as part of it, there are way fewer landmines. For me at least, TDD in a good code base is the most soothing and productive way to work I've found so far.
- Consultant32452 4y agoThis is not intended to be snippy. What makes writing tests more overwhelming and daunting than writing any other form of code?
- TylerE 4y agoIt’s very difficult to know if it’s the test that’s wrong and not the logic.
- randomdata 4y agoTests merely document expected behaviour of your application. If you are unsure of what behaviour your application should exhibit, you need to step away from the code and talk to your customers for a while.
- 4y ago
- revskill 4y agoThe issue with TDD is not about whether it's a requirement or not. It's more about what tests you write, when to write and how to write it in the most efficient way as possible.
- taeric 4y agoMy beef with TDD is the same as my beef with a lot of estimation techniques. They really need for you to have done the thing before. Faith that you "know what tests are needed" is surprisingly loaded. Unless you are writing, effectively, integration tests for specific layer. But, at that point there is no guarantee that you know how to write the magic in between. (There was an interesting attempt at a sudoku solver using TDD once. It... didn't end well.) Though, typing that last part out. Maybe the concern is over the level of the tests. Unit tests are surprisingly easy to understand based on how you have divided out the code. However, there is very little that is required on how you have done this division. Path dependence is a huge thing to define what divisions of code you will end up with. Such that I have a hard time seeing how that works in a TDD fashion.
- wpietri 4y agoI don't find much need to have done the thing before. Before I write a line of code, test or no, I usually have some idea of what the code should do. Then I run the code to see if it does what I want. So if I'm not doing TDD, I'm still doing "manual test test first"; the test is just in my head. TDD is just saying, "Let's start by automating a bit of that test and make the test fails correctly. Then we write production code until the test passes. Once it goes green, we look at what we've got, see how we like it, and maybe refactor a bit before writing the next test." If I'm totally off the map and flailing around, yeah, I won't write tests first. I'll hack at something until I have a clue. And then I'll throw that code away and write my first test. Which is something I should do regardless of whether I'm doing TDD, as scratch code like that is too messy to keep. Easier to dump it and start fresh.
- loveparade 4y agoTDD can be great if you know exactly what you're building and what you must test for, but it gets in the way when you're rapidly prototyping and exploring. Just don't be dogmatic about practices like TDD. It's always a tradeoff. Being a good engineer means understanding when the tradeoff is worth it and when it isn't. Be wary of development teams, or people, that force you to practice certain methodologies regardless of context.
- wpietri 4y agoI think it depends on what you're exploring, honestly. TDD comes out of the same circles as Extreme Programming, aka XP. In XP, there's something known as a spike, which is basically a short-lived technical prototype. If you really don't know how to tackle something, you build a quick one to throw away. In that case, yes, definitely don't do TDD, because a goal of TDD is to build up a good test suite for production code. It's not a good match for throwaway code (assuming the team really has the discipline to throw it away.) But if I'm exploring in a way that feels less disposable to me, which happens often, then I'm happy to use TDD. E.g., if I want to try out a new way of solving a problem, or I have an idea for an architectural improvement. Then I'll use TDD to force myself to think about it from the outside in, to keep design considerations to the forefront.
- LAC-Tech 4y agoTDD can be great if you know exactly what you're building and what you must test for But you should know this from your functional requirements, right? (Slightly sarcastic comment, I know in a lot of places people just start coding without a plan, but I think TDD and functional requirements go together well).
- devoutsalsa 4y agoTDD is pretty useless when the requirements are shit. It just takes longer to realize you need better directions.
- scott_w 4y ago
- ano88888 4y agoUnless you work on a big company where you're just a small cog in the machine and your work doesn't matter much, you will be defeated and destroyed by folks who move much faster at building and fixing things in this rapidly changing world. By the way Android OS wouldn't exist , if the amazing team have used TDD rather than just focusing on building good quality product and moving really fast
- wpietri 4y agoNah. I've done a startup where we did TDD and pair programming (with frequent pair rotation) for all production code. We were incredibly productive. High code quality and good tests mean you get to spend way less time on mysteries and bugs. Aggressively refactoring the system means you end up with flexible, composable units that make it easier to keep up with rapid changes. It's basically the same deal as cooking. Can I go faster if I dirty all the pans and don't worry about cleaning up? For a little while! And after that, productivity and quality drop. There's a reason that professional chefs are big on "working clean". For those interested, there's a book with a lot good interviews with chefs on their work practices. I think a lot of it translates to software: https://www.workclean.com/ https://www.workclean.com/
- karmelapple 4y agoOur company is intentionally small, we have been around for over 10 years, we move fairly fast to address needs in our market segment, and we have been doing mostly TDD for years. I highly recommend writing automated tests to guide what you do even for small companies. Perhaps especially for resource constrained ones, when every hour spent working is hard earned.
- jackblemming 4y agoThe Android OS is OK from my personal experience. I wouldn’t brag about it. Now Android App development is by far one of the worst experiences I’ve had the misfortune of having, and I repeatedly thought how everyone involved with the design of those APIs ought to be fired. Maybe they should have been using TDD!
- roeles 4y ago
- LAC-Tech 4y agoThe longer I'm in this industry the more I'm keen on a bit more formalism and upfront design. I think TDD is a really effective tool. But make no mistake - it's, requires discipline, and good software architecture. Which is my hot take on why it has so much blowback.
- devoutsalsa 4y agoIt’s hard to execute on a plan that requires everyone to be exceptional.
- LAC-Tech 4y agoI think the opposite. It's easier to have discipline and adhere to a process than it is to be exceptionally talented. (Assuming that's what you meant by 'exceptional')
- Jensson 4y agoDisciplined people are exceptional. Most people when forced to do TDD will just write a bunch of nonsense tests that adds to your technical debt, it requires discipline to write good tests.
- User23 4y agoThose people will manage to write terrible code regardless of coding technique. TDD at least has the benefit of surfacing it sooner.
- User23 4y agoAlmost always when I see criticism of TDD it quickly becomes apparent that the person doing the criticizing either has no idea how the TDD process is meant to work, has no idea how to separate concerns when writing code, or both. For example the claim that TDD impairs your ability to modify code is completely the opposite of my experience. It’s quite simple, just don’t write overly specific tests, and test your module interfaces (however your language implements them) rather than the internals. One code smell is that if your tests are getting in the way of refactoring you’re certainly doing it wrong, since refactoring is a key and I would say even defining part of the TDD development process.
- hakanderyal 4y agoI develop products much faster with automated tests. And people always ask if it's really true every time I say that. What I've found is that you need to reduce the friction to writing tests, if you want them to get written. Once it's easier to write automated tests than to test manually, the benefits are a lot more clearer. Manual testing has a much higher, but hidden, cost. If the friction is higher, tests will be forgotten amid the pressure from stakeholders and deadlines. Once you discover the benefits of low friction automated tests and write testable code by default, even you don't practice TDD by the book, you can get some of the benefits mentally. And if you are using static typing, the amount of tests you need write goes down significantly.
- faizshah 4y agoI started appreciating TDD as I’ve been using GitHub CoPilot, the results it produces become scarily accurate after you write unit tests (that it helps you write). It’s actually an amazing workflow to just write out the tests first and then generate out the implementation with copilot.
- what-no-tests 4y agoI would rather see tests with no code, than code with no tests.
- bcassedy 4y agoThis is just insanely wrong-headed. Tests with no code are always negative value, the time it took to write the tests. Code with no tests might also be negative value, but it at least has the possibility of having positive value. Tests are great and TDD is great for some people, but the whole point is to write useful software. It's important not to lose sight of that.
- randomdata 4y ago> Tests with no code are always negative value They may have negative value, but it is not a foregone conclusion. Tests are merely documentation and that documentation very well could provide positive value for someone who reads it. There is no doubt insights to be gained in reading about what someone was once thinking about a particular problem. If well thought out, you might even begin implementation based on that work, saving time having to document it all over again.
- siva7 4y agoTDD is an advanced pattern which isn't suitable for junior developers. I feel that's the main reason why TDD fails to gain momentum in many teams because those starting out still need to learn many other things before being mature enough to start with this approach
- ornornor 4y agoI disagree. I started learning programming seriously on my own, using Ruby. And TDD/testing was built into most sources I could find (books and courses, not random blog posts) so I started doing it almost right away. It’s paid huge dividends ever since and it’s not rare for me to join a larger corporate/enterprise type of environment and be the only one who seems to even be aware of automated testing as a concept.
- siva7 4y agoI've managed a few teams so far and made my observations about developers who didn't learn testing from the ground-up. TDD is not something i would describe as an intuitive concept, especially in the context of business requirements.
- albertopv 4y agoOnce I read an article about the idea that one should develop an app without even starting it in dev env, but use only automated tests. Maybe that's a bit too far, but dealing with a backend app that takes minues to start, automated tests are a godsend and I always advocate them to younger coworkers.
- doubtfuluser 4y ago+100 on this article. I observed the same in two stages of my life. 1. When I became more senior scientist - scientists usually write crappy code - but once I had a lot of other stuff like coaching, strategic planning etc on my plate I was only able to code in short bursts. Making sure I can trust my code and don’t need to wait for later stages increased my code outpu even though I was coding less time. Similar when I became a manager who loves to add code from time to time. 2. Totally in line with OP, once I got kids, I started to use TDD extensively even in my hobby projects. The tests were giving me confidence on the one hand and at the same time the documented how to use my stuff - which is important if your coding is spaced over weeks without any coding at all where life is keeping you busy. So it was for me indeed also triggered by constraints to significantly improve my productivity
- haspok 4y agoThis post seems to support my hypothesis about TDD: it is for the poor programmers. If your programming skills are limited (for whatever reason - you are junior or you are just sh*t tired or distracted) it can help you by not enforcing you to think your code through, and it enables you to make some kind of progress despite of that. (Whether that is a good thing or a bad thing - I'm not sure, but for juniors I can accept it as a viable alternative.) But the problem is that if you _only_ do TDD then you will be stuck being a poor programmer, because you will never develop the mental skills to design and hold code structures in your head beyond the trivial size. Beyond a certain point of maturity in your professional career you will just have to move past that, and then you will realize you have no use for TDD in 99% of the cases, it doesn't help you, in fact it slows you down and makes your code quality poorer.
- maest 4y agoThat's an edgy thing to post, tbh, in terms of how HN readers will take this. I think there are 2 arguments for TDD: 1. For at least some bits of your code, you would benefit from having tests. Writing tests after the fact is a pain, so might as well start with them. 2. Even for highly skilled programmers who enjoy thinking about their code deeply as they write it, there is still a class of difficult algorithms where they would benefit by writing the tests first. I'm thinking about stuff like tricky graph algorithms or scientific computations etc. That being said, I generally have found TDD to be too onerous - except for maybe 1% of the time when I do find the extra safety brought by the tests to be useful.
- Shish2k 4y ago> This post seems to support my hypothesis about TDD: it is for the poor programmers If there’s one thing I’ve learned after decades in the industry, it’s that we are all poor programmers. Our squishy wet human brains are simply not a good match for what computers do, and as such, we should take all the help we can get :)
- pcthrowaway 4y agoI think it's more that TDD is great for testing the kinds of things juniors are more capable of writing. Once you're dealing with multiple systems, or outputs dependant on the combination of an input and a complex state, unit tests aren't as easy to write or as useful.
- tpoacher 4y ago> Test Driven Development (TDD) is[…] > Specifically, it's a test first methodology, where […] I am very confused by now, since I've heard one vocal camp saying TDD=TFD, and another vocal camp saying it most definitely is not, and that TFD is in fact the black sheep of TDD and should mostly be avoided. What do people here think? (and if TDD is not necessarily TFD, then what is it exactly?)
- noisy_boy 4y agoFactor in the additional overhead of TDD and let the boss/team decide if TDD is to be used. Even if they agree on the extra 3 days on account of TDD, I would guess that people will use it for items without demanding timelines; crunch-time stuff would be exempt.