Today's Question:  What does your personal desk look like?        GIVE A SHOUT

How deep should unit test go?

  sonic0002        2012-09-03 10:11:27       4,114        0    

There is a question on Stackoverflow which says "How deep are your unit tests?". It is asked by a guy named John Nolan. The question is not too new, but what catches me is the Best Answer given by Kent Beck, who is the creator of Extreme programming(XP) and Test Driven Development(TDD).

Let's look at the question first.

The thing I've found about TDD is that its takes time to get your tests set up and being naturally lazy I always want to write as little code as possible. The first thing I seem do is test my constructor has set all the properties but is this overkill?

My question is to what level of granularity do you write you unit tests at?

..and is there a case of testing too much?

   -- John Nolan

Now lets look at the answer given by Kent Beck.

I get paid for code that works, not for tests, so my philosophy is to test as little as possible to reach a given level of confidence (I suspect this level of confidence is high compared to industry standards, but that could just be hubris). If I don't typically make a kind of mistake (like setting the wrong variables in a constructor), I don't test for it. I do tend to make sense of test errors, so I'm extra careful when I have logic with complicated conditionals. When coding on a team, I modify my strategy to carefully test code that we, collectively, tend to get wrong.

Different people will have different testing strategies based on this philosophy, but that seems reasonable to me given the immature state of understanding of how tests can best fit into the inner loop of coding. Ten or twenty years from now we'll likely have a more universal theory of which tests to write, which tests not to write, and how to tell the difference. In the meantime, experimentation seems in order.

-- Kent Beck

This answer seems negate TDD. It's a surprise, right? The creator of TDD negates TDD. Personally, I agree with Kent Beck, you should do what you like, you can do any test you like. Only if you have confidence on yourself and your team.

Software development is a knowledge based job, it's like designing artwork, there is no standard answer. Also, the quality of software is not determined by testing, it's determined by design and maintenance. So how deep you unit tests should be is not imoprtant, the important thing is that whether you know how to design your software and how to test it.

Original author :  Reference : http://coolshell.cn/articles/8209.html

TDD  UNIT TEST  XP 

Share on Facebook  Share on Twitter  Share on Weibo  Share on Reddit 

  RELATED


  0 COMMENT


No comment for this article.