TDD …how?

后端 未结 7 1028
逝去的感伤
逝去的感伤 2020-12-14 23:57

I\'m about to start out my first TDD (test-driven development) program, and I (naturally) have a TDD mental block..so I was wondering if someone could help guide me on where

7条回答
  •  南方客
    南方客 (楼主)
    2020-12-15 00:46

    When I was starting with TDD, I read these 3 rules by Uncle Bob that really helped me out:

    1. You are not allowed to write any production code unless it is to make a failing unit test pass.
    2. You are not allowed to write any more of a unit test than is sufficient to fail; and compilation failures are failures.
    3. You are not allowed to write any more production code than is sufficient to pass the one failing unit test.

    In a shorter version it would be:

    1. Write only enough of a unit test to fail.
    2. Write only enough production code to make the failing unit test pass.

    as you can see, this is very simple.

提交回复
热议问题