1

The subject of my question is a programming concept, more exactly about Test-Driven Development (TDD). Regarding Uncle Bob’s Three Laws:

You are not allowed to write any production code unless it is to make a failing unit test pass.

You are not allowed to write any more of a unit test than is sufficient to fail; and compilation failures are failures.

You are not allowed to write any more production code than is sufficient to pass the one failing unit test.

I'm not sure about one thing in the emphasized part. Does "any more of a unit test" mean I should not write additional unit tests besides the one I'm about to write, or that I should not write a longer unit test, or a unit test with more conditions/content, than the bare minimum for a failure to occur?

I'm inclined towards the former, but that particular construction makes me dubious.

1
  • 1
    It isn't very clear. I would guess it means that each unit test should be no longer than it needs to be, but that's based as much on knowledge of unit tests as of English grammar. You could compare "There isn't any more milk than (the amount) I need to make tea", meaning that after I make the tea there will be no milk left. But it's far clearer to rewrite some other way.
    – Stuart F
    Commented Aug 29, 2022 at 12:33

2 Answers 2

1

Stuart F is correct, it simply means that for any unit test you are writing, you should stop writing it once you have written enough that it fails, even if the failure is just a compiler issue rather than a failed assertion.

I agree that the phrasing is awkward, but to me it comes across as an intentional awkwardness that the writer expects a native speaker to be able to understand nonetheless. My guess is that it is a stylistic choice which is meant to make the phrase stand out, and also to create parallel sentence structure with the other two laws.

1

Per the actual source of the original post's quotation:

"by rule 2, you can't write very much of that unit test. As soon as the unit test code fails to compile, or fails an assertion, you must stop and write production code"

In other words, the original poster "should not write" "a unit test with more conditions/content, than the bare minimum for a failure to occur".

1
  • 1
    Which implies it will be a single test, so both interpretations are correct, right? The bare minimum would be a single test with a failing assertion, which may or may not include a compiler error.
    – Piovezan
    Commented Aug 30, 2022 at 16:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .