r/SoftwareEngineering • • 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!

45 Upvotes

126 comments sorted by

View all comments

Show parent comment

1

u/violated_dog Mar 19 '25

Thank you for the response, and for being a willing proxy!

I can definitely appreciate content creators needing to narrow the scope of their content, and it probably highlights my need for a more senior engineer to bounce ideas off.

In response:

  1. I’ll have a look and pick up a copy! Thanks for the recommendation.
  2. Ok I think that makes sense and I’ll work with that in mind for now.
  3. So would it be reasonable for my Port, and therefore Interface to define a hundred methods? I get that its responsibility is to interface with the DB but this feels like an overload. It would also mean that implementing a test double would require implementation of all defined methods, even if those aren’t required for tests. Though that also makes sense given that you are specifying it as a dependency of the application. Our application is CRUD heavy and exposing 4 methods per table in a single Interface doesn’t scale well. Am I focusing too hard on “Port is an Interface” and a Port can be a collection of Interface classes? My mind right now is at “Port maps to a single Interface class in code”, but I need to shift to a “Port is a description of behaviour with inputs and outputs, whether it’s defined as a single, or multiple Interface classes in code doesn’t matter”?
  4. See above.
  5. Makes sense, agree.
  6. Thanks for the detail. I like the term modulith and it accurately describes what we’d like to achieve with our structure. Were attempted to effectively refactor an entire application that is a distributed monolith, a collection of tightly coupled microservices, into a single “modulith”.

My initial approach is to try and understand how to structure the software to achieve that (hence these questions), and understand the business outside the current implementation. The documented use cases are… not valuable. So I’ve started identifying those with customer groups, and will also pull out a ubiquitous language while we’re there. Thank you for outlining your process and I feel like I’m on the right path!

My next goal is to wrap the current system with tests so we can refactor safely as we incrementally absorb the existing microservices. The system heavily automates virtual infrastructure (eg cloud resources), so many use cases seem to only align with CRUD actions on those resources, and updating metadata to track those resources in a DB. I am now getting resistance about the benefit of writing unit tests for those behaviours. EG a primary port would be triggered to create a virtual machine. This would update the cloud as well as the DB, and return a result with a representation of the created resource, implying a success. A unit test would plug in test doubles for the “cloud” and “DB” adapters, and all we’d assert on is data we’ve told our test doubles to return is returned. Is there any value in this or should I skip this and move to integration/functional tests to assert resources are modified on the platform as expected?

The only business logic applied to these use cases would be the permissions we apply on top of those actions, but that’s currently handled in another service.

We then have issues with the DB adapter also applying business logic via the form of check constraints. This makes sense so as to avoid issues where records might be inserted from outside the application such as from the shell itself. In this case, should we “double up” on the logic to also apply it within the Application itself? This is similar to front end validation that might occur, but you also validate it in the Application layer.

Sorry, this ended up longer than I thought, but thanks for your time. If it’s acceptable, I could shoot you a DM to continue the conversation further, but I completely understand if you don’t have capacity for that. Either way, thank you!

2

u/flavius-as Mar 20 '25 edited Mar 20 '25

Architecture doesn't mean you throw away good design practices or common sense. A port is in that sense a collection of interfaces sharing a goal (interface segregation principle).

When you think or communicate ideas, you do so at different levels of abstractions based on context. When your focus is a single use case, which requires a single interface for storage (among the many), you call that "the storage port". When you talk about whole components, you can call the whole component containing only (and all) interfaces responsible for storage "the storage port".

An anemic domain model is a code smell. So for crud operations, just don't forward the request further into the domain model and process them only within framework code (MVC).

But beware: https://www.linkedin.com/posts/flavius-a-0b9136b4_where-do-you-hide-your-ifs-some-examples-activity-7275783735109693441-0LSA?utm_source=share&utm_medium=member_android&rcm=ACoAABg5aA0B9xSOb2Ogc9NRHoto5TwGnqObhQg

The moment you type an "if" you are likely introducing domain rules, so then refactor that to shift into use case modelling.

The only business logic applied to these use cases would be the permissions we apply on top of those actions, but that’s currently handled in another service.

We then have issues with the DB adapter also applying business logic via the form of check constraints. This makes sense so as to avoid issues where records might be inserted from outside the application such as from the shell itself. In this case, should we “double up” on the logic to also apply it within the Application itself? This is similar to front end validation that might occur, but you also validate it in the Application layer.

Concrete examples might help but yes this is a tough question: repeated and spread validation.

You can be creative here: code generation, wasm, ...

Sorry, this ended up longer than I thought, but thanks for your time. If it’s acceptable, I could shoot you a DM to continue the conversation further, but I completely understand if you don’t have capacity for that. Either way, thank you!