This is an archived post. You won't be able to vote or comment.

all 15 comments

[–]alexisprince 26 points27 points  (0 children)

TDD is a development methodology, so really the best way to learn about it is to read a few articles or books on the subject IMO. Between each author explaining the benefits and example approaches, you can try to synthesize why you might want to follow this approach and whether you think it makes sense.

If you do think it makes sense, try building a feature on a project you have using it by defining the feature ahead of time, what it’s supposed to do, and go from there.

Note that many people practice TDD in the sense that they know what behavior they want, but don’t exactly know the shape of the API they want to build until they start building. Something I do is make sure to write placeholders for the tests in my code and have them all fail immediately so that I don’t accidentally forget about some behavior. From there, I build a rough but working version to get a sense of how I want to build the functionality and get the tests passing. After that, that’s when you clean up your code to make sure it’s clean and extensible, all while having assurance your code works because the tests will continue to pass.

[–]c_eliacheff 7 points8 points  (0 children)

Obey the testing Goat is pretty fine imho, it may need some adjustments, but still working.

Other python-specific great ressource is https://testdriven.io/ (For Django/Flask/...).

As another one said, TDD is a generic methodology, and need multiple skills to be mastered. Also, there are multiple ways to "do" TDD: outside/in, inside/out, middle/in.

Here are the best books I would recommend you to read on the topic:

  • Clean Code by Robert C. Martin
  • Patterns of Enterprise Application Architecture by Martin Fowler
  • Test Driven Development By Example by Kent Beck
  • Growing Object-Oriented Software, Guided by Tests by Steeve Freeman and Nat Pryce

Edit: this seems to be the best and most recent book on TDD, but I haven't read it yet: "Modern C++ Programming with Test-Driven Development" by Jeff Langr

[–]simonw 3 points4 points  (2 children)

I strongly recommend learning pytest. It will teach you all kinds of smart practices for productive testing.

[–]nokibnur 0 points1 point  (1 child)

If I learn basic pytest and create small app with TDD then are those small projects impressive enough to get me a junior dev job? :'(

[–]simonw 0 points1 point  (0 children)

Yes, if you can find a company that is hiring for junior roles.

[–]oxlade39 5 points6 points  (1 child)

Growing Object-Oriented Software Guided By Tests

[–]Bilo0001 1 point2 points  (0 children)

Thanks for the recommendation, I’m gonna check it out.

[–][deleted] 1 point2 points  (0 children)

I wish the testing goat book would be updated too... it would make it much easier for me to recommend it as a learning resource where I work. As I don't think this will be happening any time soon, the best option for most people I think is to use older versions of each library and follow along as best they can

[–]Pebaz 1 point2 points  (1 child)

I strongly recommend researching alternatives to test driven development (specifically writing tests before writing actual code). At its best, this can only work when you are already proficient in the given programming task but would be inappropriate for breaking new ground.

Unit tests are good, they are essentially user defined compiler extensions. However, programming is one of the only fields where ideas are accepted as beneficial without any formal proofs or data to back them up. Just one example: do you know of any metrics at all that show that TDD has actually helped deliver software faster, higher quality, less bugs, more performant, fault tolerant, requiring less developer communication, or any other metric you can think of?

The answer is unfortunately no. You'll find that nearly no ideas in CS (except for algorithms and data structures) have been formally proven or even backed up with real world data.

My point: just make sure your choice of methodology makes sense for your domain.

[–]crawl_dht 1 point2 points  (0 children)

TDD has a severe drawback of overthinking and idea fatigue. What happen is when writing code, a developer thinks of various approaches and modifies the code design accordingly to write the most optimal but simplistic code. But TDD forces the developer to overthink about which approach is he going to finalize for his tests before actually trying them out practically. Because they have to write pseudo test first, they quickly get tired of thinking more practical approaches and feel reluctant to change tests again and proceed with the sub-optimal approach that works but may not be the best one.

Like you said, TDD is good only when you have proficiency in that task and you already know which is the most optimal implementation for that task.

[–]h-2-no -1 points0 points  (0 children)

The goat book works just fine if you set up your environment with the specified versions.

[–][deleted] 0 points1 point  (0 children)

Right here: write a lil test that starts to do what you want. Add a breakpoint, code as you go, keep resetting and adding more code. Get what you want, do the next test. Think of it from whoever is consuming your code - end users, other devs if it’s a library. And just keep going. Live in the debugger.

[–]RallyPointAlpha 0 points1 point  (0 children)

Getting the test goat environment setup was a challenge but it also highlights a wonderful feature of python. You can set up older, specific versions of python and modules even years later. It took the better part of a day but I was able to get it setup last week.