r/SoftwareEngineering • u/Aer93 • Mar 10 '25
TDD on Trial: Does Test-Driven Development Really Work?
I've been exploring Test-Driven Development (TDD) and its practical impact for quite some time, especially in challenging domains such as 3D software or game development. One thing I've noticed is the significant lack of clear, real-world examples demonstrating TDD’s effectiveness in these fields.
Apart from the well-documented experiences shared by the developers of Sea of Thieves, it's difficult to find detailed industry examples showcasing successful TDD practices (please share if you know more well documented cases!).
On the contrary, influential developers and content creators often openly question or criticize TDD, shaping perceptions—particularly among new developers.
Having personally experimented with TDD and observed substantial benefits, I'm curious about the community's experiences:
- Have you successfully applied TDD in complex areas like game development or 3D software?
- How do you view or respond to the common criticisms of TDD voiced by prominent figures?
I'm currently working on a humorous, Phoenix Wright-inspired parody addressing popular misconceptions about TDD, where the different popular criticism are brought to trial. Your input on common misconceptions, critiques, and arguments against TDD would be extremely valuable to me!
Thanks for sharing your insights!
58
u/flavius-as Mar 10 '25 edited Mar 10 '25 •
I'm not working on games, but complex finance and e-commerce software.
It works, but the problem is that the key word in TDD is not testing, it's everything else.
Tidbits:
Without experience in game development, in P&A I imagine the application consists of the game mechanics, completely isolated from the display. A unit would be a single command. In business-centric application we would call that an use case.
The rendering etc would be adapters implementing the ports.
6
u/greyeye77 Mar 10 '25
ask any devs to write unit test to old/legacy code that didnt have unit test to start with, refactoring is super hard without risking breaking something. This is why if company have policy such as TDD, it helps to design the code base to have tests.
While tests cannot cover all failures, it certainly reduces some of the risk when refactoring or adding new features.
you pay with your time and some added complexity in the beginnings but I believe it's worth it for the long run.
2
u/VegetableMail1477 Mar 10 '25
Okey, so I’ve heard a lot about testing and its benefits. I’m rather new to the industry (3yrs) and I have tried on multiple occasions to use TDD and tests in general. This has been on my own initiative as the teams did not really care.
The thing I struggle with is the conceptual part of tests. What should I test? Why are integration tests not sufficient enough? In general I find tests to be confusing. And creating a simple framework around it has also been hard.
But I believe TDD and tests in general are better suited for complex systems. For simple systems it seems to be more code to maintain. However, I know that my views are probably scewed as I haven’t understood the paradigm properly.
2
u/Independent_Pitch598 Mar 10 '25
Yes with AI it shines.
2
u/UnkelRambo Mar 13 '25 •
I can't commit the time to read this whole conversation, but I'll give my $0.02 as a game dev who's written a lot of low level code...
The tree metaphor strikes again!
TDD only works well for lower level "trunk" code like math libraries and such, IMHO. It does not work very well for "branch" code like systems or "leaf" code like individual, client facing features.
Trunk code by its highly reused nature must be heavily unit tested, meaning a "functional" unit of flow control not necessarily "code coverage". These logical cases are usually simple to enumerate, especially in stateless, functional library code, and therefore are great candidates for TDD. Write all your tests verifying your expected outputs, then make the code do that. Easy. Useful. Highly recommended. Trunk code is typically high FAN-IN, meaning it's referenced by other code and worth guarding against unintended side effects of an internal change.
"Branch" code, on the other hand, tends to be more high FAN-OUT, typically more "integration testing" heavy, and higher change than Trunk code. It's not a great fit for TDD because the logical paths code can take are often more complex, the code is more stateful, and has more dependencies. TDD can be done, but it's often a debate whether the effort is worth it if a whole system needs to be rewritten or replaced.
"Leaf" code comes and goes, is iterated on frequently, and tends to be almost entirely FAN-OUT, meaning it uses lots of Branch and Trunk code. Because of the fast-paced nature of change to Leaf code and it's focus on "user testing", TDD doesn't make sense. The test cases you care about are all human behavior, not necessarily code execution. It's not the end of the world if your one-off feature doesn't perfectly handle every edge case.
Now, Sea of Thieves is an interesting example. I was at Microsoft when it was being made, though not in that team, I worked with people who were. That team spent a while lot of time writing highly tested code for a relatively simple game that wasn't that good when it launched. Getting it good took time, and some of my colleagues argued that it was because TDD slowed iteration down too much. They made a highly tested codebase that passed "functional" testing, but failed "user" testing (in that it wasn't very fun.) But I wasn't there so take it with a grain of salt...
I use TDD heavily in game development, but only for core "Trunk" libraries that I reuse all over the place. I don't go near TDD for gameplay systems or feature development because it's complex, takes a lot of effort, and doesn't necessarily yield impactful results. Half the time I don't know what I want a system to do until I build it and try it 🤣
TLDR: TDD makes sense for lower level"Trunk" code but that's about it. Strict adherence to TDD can cripple iteration time which is necessary for game development.
Great question, hope this is helpful!
7
u/pyhacker0 Mar 10 '25
IMO the only people who criticize TDD are people who never actually practiced TDD. TDD improves code quality and velocity. You never see developers attain 100% test coverage unless they practice TDD
3
u/Mithrandir2k16 Mar 10 '25 edited Mar 10 '25
IIRC Larian the Baldurs Gate 3 devs have descibed a workflow that was either TDD or prevented commits that lowered test coverage.
Personally I use it a lot, though for me switching to it very early in my career was easy, because I used to hop into some REPL to validate my assumptions about how the code worked a lot. Switching to TDD then was just writing the assumptions down as a test first, then implement code that fulfilled them and skip the REPL for some test runner.
An unexpected benefit of TDD is that if you need to work on multiple projects at a time, stopping work always meant leaving a red test uncommitted/unpushed/pushed to a branch, then once I come back to the project days or weeks alter, I just run the testsuite and my first TODO item is shown to me in red right away.
3
u/sneradicus Mar 11 '25
I can’t speak for other disciplines, but TDD can be useful in the embedded world where flashing bad code can cause serious issues.
3
u/TedditBlatherflag Mar 12 '25
Most folks I know who are very senior (10+ years) intuitively practice a hybrid form of TDD where they will write small understandable pieces, get it under exercise tests validating it, and use those pieces to build up more complex pieces, and once the design is settled out and unlikely to need a refactor, then go back and start to build out edge tests and error case tests.
It’s a bit of the inverse to the test-first and code to the test result of dogmatic TDD but in practice is mostly the same.
There space where TDD really shines for me is when developing libraries or apis where you know how you want them to appear and what they should do publicly, but are unsure of the implementation details or how it should work internally.
Then defining those tests which describe the API first and implementing to the test works very well and can be a great thought exercise to get rolling.
I think any software design pattern or methodology is ultimately not going to be a one size fits all solution.
But good test practices really do improve development. The number of really good developers I’ve seen who used to lean on a REPL but then tried TDD and ultimately land in a hybrid approach where anything that would’ve been REPL becomes a test is near 100% of devs. And all their REPL usage drops to nearly nothing.
3
u/HKSpadez Mar 12 '25
Working on cloud and fullstack. TDD has actually been a huge time saver while enforcing high standards in our code base. It's a win-win. But definitely not suitable for every project/product
5
u/RedditMapz Mar 10 '25 edited Mar 10 '25
Personally I think it works but it requires buy-in from the team to work for you
The good
TDD makes you think about your front facing interface and architecture ahead of time. This is a good practice for an experienced developer to follow. It allows you think through some corner cards and complexities ahead of time and probably lead to better time estimates. It also encourages you to write smaller units code with single responsibilities. Unit tests written are not afterthought so they might actually have meaningful coverage. In my experience it does lead to less bugs and faster development cycles due to the reduction of risk and the QA back and forth time.
The bad
It absolutely takes more time to develop initially because it requires thinking in more detail and writing more code. And that is a big problem. A company that focuses on quantity rather than quality (say your bonus depends on how many sprint points you complete), basically encourages people to bypass tests altogether or at the very least meaningful and detailed tests.
Personally
I Ied with good practices the best I can in the projects I lead. I just had this happen to me recently where I joined a team to lead a project that was falling behind last year. I reviewed all the software components with the team. I worked with them for a week to redesign the architecture ( on paper). And ultimately rewrote (with them) almost everything including the addition of unit tests for testable units. We also wrote many pages of detailed documentation. The amount of times I got put through the ringer for not hitting artificial internal deadlines set by management was too many. I have a seniority and a lot of credibility so I could pull it off, but I don't blame people for falling in line instead.
A year later, this is the only big feature that is on-time, stable, and working as intended. Everything else that was rushed failed at some point due to excessive risk (technical debt) blowing up. Not just TDD, but I think good practices have their merits, they are just not often supported or rewarded.
1
u/Shulrak Mar 10 '25
For games check out the automated testing in gamedev discord there are few resources and they have a monthly a you can discuss things
Beside sea of thieves, there is also rollerdrome (there are few talks)
(Just to clarify) TDD is different than just having tests. In the gamedev industry it's already hard to just have tests due to misconceptions etc, so TDD is another beast.
Note that I don't work in gamedev but I was looking to make a switch and I used TDD extensively in finance and core infrastructure in big companies
2
u/Large-Style-8355 Mar 11 '25
Beeing a long term fan of TDD myself (embedded and distributed systems, com protocols) and I'm know for always stressing "if it's not tested - it won't work". In my domain it's typically even harder and more effort to build testing setups which allow you to make sure a change is not breaking everything or introducing subtle issues. Over the years while building and leading the development of larger and larger systems I mostly setup testing schemes verifying on multiple layers from functions (testing known results, boundaries, overflows) to modules / libraries, whole subsystems using mockups, buses etc, and whole distributed systems either running in simulators and or on semiautomated test rigs with all hardware, software and communication components in place. I'm always pushing to test most if not all things stated in requirements, user stories, spec sheets as often as possible. During each build, nightly, weekly, on each release.
2
u/theScottyJam Mar 12 '25 •
This is going to be long-winded, sorry. Guess I have a lot on my mind about the subject.
Anything to help demystify TDD is welcome. TDD is such a difficult topic to study, especially from an outsider's perspective, because:
A bit of my background: I care a lot about testing. We follow a ports-and-adaptera-like architecture, and we heavily unit tests the pure code inside. Any time we check in new code, we're also supposed to check in unit tests to cover that code. The tickets we work on are broken down to be fairly small, so we're often submitting small-ish changes and reviewing each other's work. As I work, I keep an open editor with notes on what I'm doing and things I still need to do (I mention this, because I know Kent Beck happens to recommend doing that sort of thing in his book).
But I don't do TDD. And when I read online about all the reasons I should do TDD, I often see stuff like this in the list:
Being a "driven developer" gives you all of the advantages listed above. If, whenever I start a ticket, I create a todo list that starts with "design the public APIs" and ends with "cleanup code" and "write tests", and I follow the YAGNI principle as I code, then I've got the same benefits that these articles ascribe to TDD. When I read about TDD, I want to know what's special about being "test driven". I admit that, perhaps I'm being a little stingent about this - I can see a desire to express things like "if you weren't good at doing X before, once you start doing TDD, it'll force you to be better at X", but usually it's written as "TDD makes you better at X", and sometimes it's almost treated as magic, where it's impossible to achieve the same level of X unless you do TDD. (Where X is one of the virtues from the above list), and this kind of talk really hurts the reputation of TDD.
The only unique advantage I personally see that TDD could give me when compared to what I already do is development speed.
I hesitate saying all of this, because I know there's no real good definition for a "driven developer", which makes it a bit fuzzy to figure out if something is a TDD advantage or not, and so I'm fine if people disagree with what I say is and isn't an advantage. But either way, when presenting these advantages to non-TDD folks, if the readers can see easy ways to get the same advantage without following a test-first methology, or maybe they already get the same advantage with what they're already doing, then the writing will come off as not being completely honest about TDD.
2. TDD fans rarely teach you how to do TDD with side effects.
Kent Beck's book on TDD walks through two complete examples, neither of which deals with side effects. In the whole book, he only discusses side effects briefly, for about a page. Most online introductions explain how to do TDD, but also don't mention side effects. Sometimes the online introductions fail to even explain how important it is to not view unit testing as "testing every module/class in isolation".
As you can imagine, someone from the outside looking in, and bringing their own understanding of how unit testing is supposed to work can get really confused as to how TDD applies in any real code. We see this confusion pop up all the time in anti-tdd comments, most of which come from people who understand the TDD cycle, but don't see how it fits in with how they currently test.
From what I gather, a ports-and-adapter style architecture is probably the best way to handle side effects, but most developers don't use that, and that's certainly not plastered across introductory TDD material.
3. TDD focuses on greenfield development.
How does TDD apply when I'm changing the behaviors of existing features, or removing features? People talk about how great it is that you can test your tests by doing TDD (by writing your implementation afterwards), but when you change your implementation, how do you retest your tests? For being a general philosophy on development, it's oddly focused on only one aspect of development.
4. No one seems to have a consistent understanding of why TDD is useful.
I said that a ports-and-adaptera architecture is probably the best way to do TDD, but that's not a generally agreed upon statement. I asked questions in point 3, and you probably have answers to them, but again, those answers aren't generally agreed upon. In many regards, TDD is only half of a philosophy, the missing half is often debated, left out of introductory material, and is left for each person to figure out on their own.
I want to touch on that "unique advantage" I perceive that TDD has compared to being a driven developer - development speed. We generally write more unit tests than integration ones because they run faster, which in turn makes a developer more productive. And TDD makes a developer even more productive because they can verify that their code works through quick-running automated tests instead of slower manual tests. But there's also a development cost to all of this. • We have to use a test-friendly architecture. It takes extra time to design the interfaces for each adapter and it takes exta time to read and maintain the code with it's extra indirection. • we have to design and use test doubles in our tests, which makes it take extra time to write those tests. • whenever we have to change the API of our adapters, we have to adjust a ton of our tests as well. We strive to make the API as stable as possible to prevent this, but still, it's a problem unique to unit testing.
Recently, I've been wondering if unit testing is overblown. Am I really gaining more development speed, despite all of those costs described above? If most of my tests were written as integration tests, the test suit would run slower, yes, but I also spend a lot less time with test doubles, and my tests become more reliable. I know I'm not the only one who thinks like this, there's talk online if moving towards a "testing diamond" instead of a pyramid. If I were to make such a move, then TDD would become impossible in the codebase. But the time I could save...
2
u/W17K0 Mar 12 '25
Tdd is a tool in your toolset. Can you apply it to everything? Sure. Is it efficient to do so? Nope
Learn when and where to use it
2
u/finally-anna Mar 14 '25 •
In my experience, one of the bigger reasons for people to find TDD distasteful is that they don't necessarily understand the "why" of doing it, which leads to the "how" being done incorrectly. Many people see TDD as having to write tests that cover all of the code base, and in doing so that it bloats that codebase. The reality is that TDD is a tool that, when used effectively, promotes smaller, more maintainable codebases, increases the ability of new developers to come up to speed quickly, and allows teams to ship high-quality features more quickly and with less financial risk.
One thing I've found effective when teaching clients how to start with TDD, and how to incorporate it into their existing applications, is that small, intentional changes are more efficient than sweeping changes across those applications. Intentionality is important in this context, and requires a fair bit of discipline. Organizations that want to use TDD have to ensure that the costs and ROI are viable over a longer period than expected.
Another important piece in TDD is starting as close to the "user" as possible, and working your way backwards. It's counterintuitive, but will generally make your code more efficient, reduce risk, and improve your ability to fix issues in a timely manner. All while reducing the total amount of code you have to write. Starting at the user and moving backwards means you write the bare minimum amount of code to get your application running. And that's an important distinction.
As an example, let's say you want to make a REST API to play a game. You could start by creating models for the user and the game state. You could create factories and repositories for creating and storing objects in your game. You could add functions that you think will be necessary to get your game to run.
Or, you could start by looking at what the user is trying to do. In trying to create a new game, you create the API that creates the game. As you progress, you create things that are needed specifically to reach that one goal. You don't create anything you don't need, and you use your unit tests to cover the logic of what you want the user to do.
So much of TDD happens outside of the code editor, from breaking stories down into appropriate slices of work that deliver value, to determining appropriate user journeys in an application. Much of it requires a deep understanding of "why" you want to do something as equally as "what" you want to do.
I'm happy to have a broader discussion about TDD and how to incorporate it into the development process.
Source: I am a Thoughtworker with experience helping clients implement Engineering Effectiveness and SLDC Modernization across a wide range of sectors and business sizes.
0
u/[deleted] Mar 10 '25
It works, but it makes your developers dread their existence and therefore produce results at like 20% capacity
1
u/Defalt0_0 Apr 24 '25
TDD is just a myth, at least in east Asia.
Developers and engineers here alike don't really write tests for development.
I think this concept only exists and relevant in the west.
1
u/BoxingFan88 Jul 03 '25
Tdd is a mindset
Write a test or proof
Then write the code that passes that test
Etc etc
Unless it's a really complicated algorithm I test at the highest level possible with no mocking.
1
u/vocumsineratio Mar 10 '25
The criticisms aren't entirely without merit.
One thing that I like to keep in mind is that "continuous integration" and "test first development" (which was, depending on your point of view, either a precursor to, or the original branding of, TDD) were both popularized at roughly the same time -- they were core practices of Extreme Programming, and escaped from there into the Agile communities, and then from there spread everywhere else.
And if you look today, continuous integration is everywhere, and widely recognized as a Good Idea; TDD... isn't.
So either TDD isn't as universally applicable as CI, or you have to be much better at it before the positive ROI appears, or some other thing that has made it more difficult to onboard the rest of the world.
And other than "Clap Louder!" and "No True Scotsman has ever failed at TDD", the literature in support of TDD sucks at making a case for it (there are some exceptions -- but there are a lot more poor examples than good ones).
And, for games development, it really doesn't help that much of the core of TDD came out of the Smalltalk community of the 90s, where lots of tiny objects were considered to be best practice -- which is probably not something you want in the middle of your game loop (Irony: Kent Beck was originally brought into the Chrysler Comprehensive Compensation project to address the performance problems they were seeing in the solution that had developed to that point).
With the payroll system, Beck's team was able to fix a happy path, then support some exceptions, then the exceptions to those exceptions, then the exceptions to the exceptions to the exceptions.... and 10 months later, even though you are so far into the maze of opaque rules that you can no longer see the light, the early behaviors that you fixed with your first tests are still correct.
But if you don't have that kind of stability in your feature set, the trade-offs of writing your tests before your code change dramatically.
0
u/thedragonturtle Mar 10 '25
Me personally, I never ever got on board with Mock data for tests - there are so many times when they give false confidence either because there is a bug in the real data creation code or a bug from interaction with other parts of the system. Integration tests, on the other hand, and regression tests to ensure no fixed bugs get reintroduced, those are awesome - but integration tests definitely do not get enough coverage or examples given.
Now - with AI development - I'm moving towards simplified test driven development, but again - not with mock data - I have scripts which add data to an empty system through official REST API endpoints and test as part of this.
Really, with AI development - my interest in TDD has increased massively since with good and proper tests you can almost guarantee that you can leave the AI to do its job and it will complete it correctly.
So my flow, as it currently stands - I get roocode/claude to create tests in a .tests folder which can be called from the command line and I have it create a visual interface where I can view and run these tests manually. This test interface will create real data through the real interfaces and then run tests to confirm the results are as expected. However, I still am not really starting with the tests - not yet.
0
u/[deleted] Mar 13 '25
[deleted] — view deleted comment
1
u/[deleted] Nov 07 '25
[removed] — view removed comment
1
u/[deleted] Nov 07 '25
[removed] — view removed comment
1
u/[deleted] Nov 07 '25
[removed] — view removed comment