3 ms·
Testing basically breaks down into the following types (and you can flavor them however you want, but take this as a starting point): - test-last testing to te
by eropple 8y ago
Testing basically breaks down into the following types (and you can flavor them however you want, but take this as a starting point):
- test-last testing to test the implementation you just wrote
- test-first testing to test the implementation you're gonna write
- test-driven design, where the tests reflect the specification and are applied to the implementation
So, with these on hand, here's my litmus test for TDD:
Do I know what I'm building and why?
You can't meaningfully do test-driven design if you don't know the what and the why. TDD tests need to encode "the business cares about this", and IME, the questions you are asking often arise when somebody doesn't really yet know what they're building. You're figuring it out. And that is okay, too!
I'm not a TDD devotee (in that I would love to write code in a TDD fashion much more than I actually do, but I think it's probably the right answer for most situations where the unknowns have been solved or pushed out) and I think that you're describing a very common situation where writing tests while you're writing code, or maybe even after--though this is often fraught--is totally fine. I regularly build systems by writing tests to exercise bits and pieces of them in lieu of opening a REPL or running it through a command line; the Test Cops aren't gonna come get you if this works better during your exploratory phase. (It does mean your exploratory phase has some useful artifacts when it's done, though.)
Put another way: if I have a spec, I can do TDD. If I don't, I can't, and I don't lose sleep over it.
- gt_ 8y agoHilarious about the test cops. Testing seems to, so far, be a fairly wishy-washy task. The spec thing makes a lot of sense. The project I’m learning with is not ideal because the test environment takes a moment to boot but it’s peculiar and challenging me to consider real-world scenarios, which may or may not be a good thing but I’m near wrapping it up. It’s a plug-in for a few different content creation softwares. I would say I knew what I was building, but there have been unknowns about which particular approach will meet my standards and still be DRY. They all worked great with prototypes but I discovered some edge cases late in construction. I found TDD very satisfying but now I have an instinctual doubt about it. Your thoughts make a lot of sense. I guess one of the main things will do next time is avoid all the extra unit testing I did early on. I think I was honestly having too much fun. Someone should do research on if automated test coverage illicits the slot-machine effect.
- swish_bob 8y agoIf you don't know what you're doing, how can you do it? I don't see how this is a TDD thing or not ...
- eropple 8y agoYou've never written exploratory code before?