When to write a test to force you to fix a Bug

62 views
Skip to first unread message

Dave Schinkel

unread,
Oct 13, 2015, 5:41:12 PM10/13/15
to Clean Code Discussion
You've got a set of tests that were running green.  You are off the project for a while (just hypothetical example) and you pop back on.  You notice you test drive again some new features on it.  Some changes you made test driving new features broke some existing tests.

Should you:

a) change the implementation of your new code or change the implementation of the existing code to get the old tests to run red again

-or-

b) write a new tests that forces you to somehow fix the old tests that are bombing out

I guess my question is, with TDD when should you write a test, to force you to fix broken tests.  I remember seeing UB write new tests and other people to fix broken code...when are those scenarios and how do you go about that properly.  Or am I just not making sense whatsoever, you tell me.

Jakob Holderbaum

unread,
Oct 14, 2015, 2:10:45 AM10/14/15
to clean-code...@googlegroups.com
I think that depends. As always :)

If the new functionality is clearly contrary to the old one, the older
contrary tests have become superfluous. If the new functionality is an
add-on to your existing functionality, you probably are better off to
iterate your code in a way that does not break the old but still valid
tests.

Do you have a concrete example?

Cheers
Jakob
> --
> The only way to go fast is to go well.
> ---
> You received this message because you are subscribed to the Google
> Groups "Clean Code Discussion" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to clean-code-discu...@googlegroups.com
> <mailto:clean-code-discu...@googlegroups.com>.
> To post to this group, send email to
> clean-code...@googlegroups.com
> <mailto:clean-code...@googlegroups.com>.
> Visit this group at http://groups.google.com/group/clean-code-discussion.

--
Jakob Holderbaum, M.Sc.
Consulting Software Engineer

0049 176 637 297 71
http://jakob.io/
http://jakob.io/mentoring/
ja...@holderbaum.io
@hldrbm

Norbert Nemes

unread,
Oct 14, 2015, 4:58:37 PM10/14/15
to Clean Code Discussion
You have 2 scenarios on your hand:
1) The specs changed and the old tests have become bad tests and should be fixed/deleted.
2) Your implementation is buggy and you need another test to fix the bug. (Unless it's the UI we're talking about)

Phil Markgraf

unread,
Oct 14, 2015, 5:53:16 PM10/14/15
to clean-code...@googlegroups.com
Or the specs are incomplete and need to be updated to support both functionalities.
> --
> The only way to go fast is to go well.
> ---
> You received this message because you are subscribed to the Google Groups "Clean Code Discussion" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to clean-code-discu...@googlegroups.com.
> To post to this group, send email to clean-code...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages