News for hackers. Stuff that matters.
Re:Is TDD Dead? (2014) by rpadovani on Wednesday August 26, 2020 @08:38AM (#24281833)
> one test per bug fixed

this, and you should try to write the test before fixing the bug - you cannot trust a test that you haven't seen failing

Re:Is TDD Dead? (2014) by parenthesis on Wednesday August 26, 2020 @09:51AM (#24282439)
I often find that before I've diagnosed and fixed a bug, I don't know what the best test is.

So I tend to: fix the bug; write the test; see the test fail on the old version of the code; see the test pass on the new version of the code.

Something else I'll throw in on tests. Many times I've caught a bug I would otherwise be introducing because an existing test — which wasn't written to catch my new mistake — fails.

Re:Is TDD Dead? (2014) by karmelapple on Wednesday August 26, 2020 @08:46AM (#24281902)
Sometimes you’re in a hurry to fix a bug, so you write the functionality and ship it out fast after some manual testing, without an automated test reproducing the bug. That’s okay!

Write the test afterwards in some branch, and after committing the tests, make an extra commit that undoes the bug fix. Let your CI run it and confirm it fails there, then bring back the bug fix on the next commit.

That way, you can have flexibility to fix things fast, but still keep the regression test that’s proven to check for it around for the future.

Re:Is TDD Dead? (2014) by afarrell on Wednesday August 26, 2020 @09:23AM (#24282211)
> to fix things fast

Note that if you see _another_ developer taking the time to write a test when you wouldn't, it doesn't necessarily mean they are wasting time.

As I am debugging something, I need to write myself a very clear description of my hypothesis of the steps to reproduce the bug -- otherwise it is hard to see incremental progress. I work faster if I can have the machine execute those steps.

Re:Is TDD Dead? (2014) by karmelapple on Wednesday August 26, 2020 @04:02PM (#24286636)
Fully agreed. I didn't intend to imply a developer writing a test is wasting time, either!

Our team has been in situations where we're highly confident of the root cause, but we know creating a test to duplicate this might take hours, if not days. It might even be a fairly finicky scenario to try and setup.

Rather than letting customers have to handle the negative consequence of our bug for hours, we'll make the change, run it through our existing test suite (to make sure we're not making yet more troubles for ourselves!), and then release it after another teammate reviews the change.

But a test certainly will help with the confidence that the right thing was changed. I would definitely encourage writing a test if it's easy for your group to handle whatever negative consequences the bug existing in the wild is producing for as long as it takes to write a test.

Re:Is TDD Dead? (2014) by solarengineer on Wednesday August 26, 2020 @09:59AM (#24282519)
"That's okay!"

Why is that Ok? How does the dev know that they've not undone anything else? Also, how does the dev know that the fix is complete? Or that it caters to the defect?

This anxiety of pushing out at fix - at the risk of undoing other working functionality - ought to be addressed first. It is better (and safer) to get into the habit of writing a test to reproduce the defect and then write the fix. After all, if the fix appears trivial, then the test for the defect ought not to take too much time either. I have been able to get to this mindset with practice.

Re:Is TDD Dead? (2014) by kyralis on Wednesday August 26, 2020 @10:15AM (#24282652)
Because being dogmatic is exactly what causes people to start ignoring this sort of methodology. Pragmatism really does have to win out sometimes. Maybe you're in a hurry because the bug is causing active downtime. Some bugs really are "obvious" once they've failed and you're looking at the code. Maybe development of a proper test involves some test infrastructure work that's a larger undertaking than you have the opportunity for at the moment. Maybe you have a solid manual/QA testing system behind you, allowing you at least temporary assurance that your fix is valid.

No team does everything perfectly all the time, and that's fine. The real question is what gets done about it afterward: is the technical debt that you've incurred paid down in a reasonable time frame?

Re:Is TDD Dead? (2014) by karmelapple on Wednesday August 26, 2020 @04:15PM (#24286769)
This nicely encapsulates what I was hoping to say, but didn't take the time to write out. Thank you!

> Maybe development of a proper test involves some test infrastructure work that's a larger undertaking than you have the opportunity for at the moment.

This is something I've encountered many times.

> Maybe you have a solid manual/QA testing system behind you, allowing you at least temporary assurance that your fix is valid.

I would hope most people are doing this anyway, especially when a big production bug has been found.

Re:Is TDD Dead? (2014) by magicalhippo on Wednesday August 26, 2020 @10:42AM (#24282910)
I've fixed plenty of bugs which I could not reproduce and thus could not test, simply based on the source code and description of problem from customer. Based on the symptoms it was clear what the code must be doing, studying the code reveals it is clearly wrong, and so the fix was obvious.

So make a patch, make a new build, send to customer and get a call "yeah that fixed it, thanks!".

Sometimes the issue is I simply don't have time to reproduce it, like that time a blocking bug had to be fixed within 30 minutes, or the customer would have had to charter their own helicopter to get a few packages to an offshore oil platform, rather than piggy-back on the worker transport heli.

Other times it's some combination of the customers system it's running on and configuration of our software that I can't reproduce.

Not saying it's ideal, but it's quite possible to successfully fix issues without being able to reproduce and test.

Re:Is TDD Dead? (2014) by bluGill on Wednesday August 26, 2020 @11:51AM (#24283578)
I once fixed a bug like that, then went wait a minute. Sure enough source control revealed I'd made exactly the same fix 2 years ago, and 2 years before that someone else had done exactly the same. In the odd years someone else undid that fix to fix a different bug that seemed unrelated. Once I figured out what the other problem was I was able to find the more complex fix for both situations.

I wished I had heard of automated tests then

Re:Is TDD Dead? (2014) by magicalhippo on Wednesday August 26, 2020 @02:21PM (#24285510)
Yeah I always check source control (blame/annotate), even if I wrote the code myself, just to be sure I'm not missing some context.

Automated tests is pretty great, but a lot of the stuff we do is difficult to test, mostly due to a lot of legacy code that's not well confined. As we work on a piece of code we try to clean that part up, but it takes time.

Re:Is TDD Dead? (2014) by smileypete on Saturday August 29, 2020 @03:30AM (#24314391)
Maybe add a dated note as a code comment breifly describing the reason for the change.
Re:Is TDD Dead? (2014) by hnick on Thursday August 27, 2020 @01:31AM (#24290425)
I'd imagine stuff like race conditions would fit into this category nicely. Obvious upon inspection but annoying to test for.
Re:Is TDD Dead? (2014) by pydry on Wednesday August 26, 2020 @11:16AM (#24283209)
>Why is that Ok? How does the dev know that they've not undone anything else?

If the bug is "I thought we were supposed to have a 10 minute timeout and we accidentally set the timeout to 10 seconds" it's pretty screamingly obvious that if you change the time from "10" to "600" the problem is now solved and you haven't broken anything else.

Religiously applying this rule of thumb as you describe causes ALL sorts of problems including the problem of people writing tests for the above kind of behavior. That test will fail when it's changed from 600 to 1800 deliberately and that will create a pointless waste of time for everybody.

Re:Is TDD Dead? (2014) by Joker_vD on Wednesday August 26, 2020 @07:34PM (#24288529)
Yeah, and then you find out that that constant was also used in another piece of code as number of minutes, so you've just changed another timeout in the system from 10 minutes to 10 hours.

Yes, of course that constant should never have been a naked integer in the first place, but we live in an imperfect world. One thing I like about Go's standard library is that almost everything takes time.Duration instead of a plain integer that's then interpreted to be milliseconds (or micro/nanoseconds in the most unexpected place, gotcha, developer, you should've read the docs!)

Re:Is TDD Dead? (2014) by leonroy on Wednesday August 26, 2020 @11:23AM (#24283268)
> This anxiety of pushing out at fix - at the risk of undoing other working functionality - ought to be addressed first.

It really depends on how urgent the fix is. Naturally you want the fix to be as isolated as possible so it does not regress other functionality. But even non-urgent fixes can sometimes benefit from getting pushed out following quick manual testing. For example we use Sentry.io for capturing errors in our applications and LogDNA for logging.

Occassionally we'll encounter some kind of edge case where we see a spike in logged errors which blows us past our Sentry and LogDNA quotas. Pushing a fix out before the test is written can be beneficial in cases like this although yes, it's worth avoiding if possible.

Re:Is TDD Dead? (2014) by karmelapple on Wednesday August 26, 2020 @04:13PM (#24286743)
Sounds like I could have been more thorough in describing why I think "that's okay."

> How does the dev know that they've not undone anything else?

I didn't write it, but I was assuming a scenario where a system already has a comprehensive automated test suite. If you have most functionality under test, then hopefully you're pretty confident that it won't undo anything else.

> Also, how does the dev know that the fix is complete?

The same way a dev knows if one single automated test that addresses the one known failure scenario is a complete fix.

In other words: you don't know. You keep doing some manual testing, and watching whatever logs or status indicators, to see if things go back to normal after deployment.

> Or that it caters to the defect?

I also didn't write this, but I had in mind some level of manual testing before deploying the code change to ensure it caters to the defect.

> Why is that Ok?

Hopefully my answers above help explain why I said that's okay.

I'm not advocating for flippantly shipping code without having a variety of other guard rails in place; I was primarily talking about when a bug has really bad consequences for users, your team is confident that writing a test is going to take a long time, and you do some level of manual testing to confirm all seems generally well.

Re:Is TDD Dead? (2014) by KptMarchewa on Thursday August 27, 2020 @07:49AM (#24292700)
>How does the dev know that they've not undone anything else?

No one says that rest of the test suite is not run.

Re:Is TDD Dead? (2014) by tonyedgecombe on Wednesday August 26, 2020 @10:27AM (#24282760)
Sometimes you’re in a hurry to fix a bug

Most of the time I find it faster to write the test first. If you haven't got a test what are you going to do? Manually test?

Re:Is TDD Dead? (2014) by MockObject on Wednesday August 26, 2020 @11:04AM (#24283094)
And since everything usually takes longer than expected, the benefit of automating that manual testing is usually greater than expected.
Re:Is TDD Dead? (2014) by hnick on Thursday August 27, 2020 @01:35AM (#24290447)
We tend to have a web focus on this site but not all IT is like that.

If I have a data processing job that takes 3 hours and it fell over at the 1 hour mark (and let's say whoever wrote it didn't have the foresight to make it resume neatly, because that's added complexity that never got budgeted), I'm going to fix the obvious bug and kick off reprocessing immediately. Possibly after some messing around in a REPL to confirm how the code acts.

While it's going, I can then do some manual tests and sanity checks and cancel/restart if necessary - but if not, I've gained a lot of time.

Re:Is TDD Dead? (2014) by dhosek on Wednesday August 26, 2020 @10:40AM (#24282900)
Nope. With experience comes wisdom. I've had the situation happen when I was sure I knew what the bug was. I wrote a test that I expected to fail—and it passed. My diagnosis was incorrect and the bug was somewhere else. Had I not done this, I might have not only not fixed the bug, I would have likely introduced new bugs.
Re:Is TDD Dead? (2014) by rad_gruchalski on Wednesday August 26, 2020 @09:22AM (#24282203)
> That’s okay!

The effort put into manual tests can be committed directly to adding a test case. Furthermore, a fix should be accepted only when a full test suite with the new tests pass. Such manual testing, depending on what the issue was, may result in a regression in other parts of software. Just a thought...

Re:Is TDD Dead? (2014) by draw_down on Wednesday August 26, 2020 @08:40AM (#24281851)
I agree with the last part, but the ordering isn’t crucial. For example you can stash your changes in the implementation to check that the test fails when the change is not present and passes when it is. For this (among other reasons) it is nice to have a test runner that re-runs when it detects file changes.

The ordering is one part of TDD that always bugged me- you have to write the tests first. But I often prefer to experiment and try a couple approaches before deciding on one. Having tests first would make a lot more overhead for that way of working.

Re:Is TDD Dead? (2014) by wh33zle on Wednesday August 26, 2020 @09:10AM (#24282107)
To be fair though, if your tests are at the right abstraction level, the specific approach you are choosing for the implementation shouldn't matter for the test.

Writing the test first also forces you to think abouy what API do you actually want to expose. Once you got the API right, there is still room for experimenting.

Re:Is TDD Dead? (2014) by draw_down on Wednesday August 26, 2020 @09:18AM (#24282168)
That’s only true when you have decided what the abstraction will be. That’s my point, a lot of times you don’t know yet!
Re:Is TDD Dead? (2014) by wrs on Wednesday August 26, 2020 @11:36AM (#24283406)
In this approach you decide on the abstraction (i.e., the API) by writing example code (i.e., some tests) that uses the API. The tests are how you decide which abstraction seems to make the most sense.

It sounds like you actually implement the abstraction to decide whether it seems like the right one, which is a lot more work.

Re:Is TDD Dead? (2014) by draw_down on Wednesday August 26, 2020 @11:48AM (#24283537)
Yes, my position is that tests as client don't really tell you the truth about the abstraction because they don't represent a real usage of it.

It is better to write tests for code when you know what it is and what it should do. Tests also introduce a drag on changing strategies- if the choice you made when you wrote them is now not necessarily the optimal one, you must now change your tests or convince yourself that you were actually right the first time.

If people like to work this way then great, I'm just explaining why for me it feels bad and runs counter to my instincts.

Re:Is TDD Dead? (2014) by wh33zle on Wednesday August 26, 2020 @04:54PM (#24287159)
I think I understand what you mean. At the same time though, one crucial takeaway for me from Ian's talk is that my tests might be on a too small scale if they are not useful whilst I am changing the implementation strategy.

For example, I found it useful to ditch concepts like the testing pyramid and focus on writing e2e tests for my HTTP API instead of trying to cover everything with module or function level tests. That makes it much less likely that they need to change during refactorings and hence provide more value.

I generally think that "What is going to break this test?" is a really powerful question to ask to evaluate how good it is. Any answer apart from "a change in requirements" could be a hint that something is odd about the software design. But to ask this question, I need to write the test first or at least think about what kind of test I would write. At some point, writing the actual test might be obsolete as just thinking about it makes you realize a flaw in the design.

Other interesting questions I like to ask myself are: "How much risk is this test eliminating?" and "How costly is it to write and maintain?"

Re:Is TDD Dead? (2014) by wrs on Wednesday August 26, 2020 @05:59PM (#24287779)
In reality I tend to do both: write example client code to think through the abstraction (some call this “README-driven development”) and then write tests once the implementation is under way. Though you can get the first as a side effect of the second, I find that good tests aren’t really good example code (too fragmented, focus on edge cases, etc.).