开发者

example of unit tests preventing regression [closed]

Closed. This question is off-topic. It is not currently accepting answers.

Want to improve this question? Update the question so it's 开发者_Python百科on-topic for Stack Overflow.

Closed 11 years ago.

Improve this question

I am the only developer in my IT shop (a mid-size retailer) writing unit tests. I have been tasked by management with giving a presentation on the benefits of doing so to our developers.

One of the "aha!" moments that led to my unit-testing addiction was the realization that a unit test suite can prevent regressions in code that you would never have thought to re-test had you been testing manually (because it seemed unrelated to the change you were making).

I am looking for an example of such a test to include in the presentation. Ideally it would be "real-world" enough to have credibility, but self-contained enough to be appropriate for a classroom setting. Homebrewed tests are fine as are pointers to relevant texts. Language of implementation is not important.


Well consider the case of a factorial function: what are the various cases that you will cover for this:

a) It returns a value for 0

b) what happens if the number is negative

c) does it return the right values for two different numbers.

Now you have an implementation written for the same in some way. Tomorrow if someone decides to rewrite the same using a recursive function it should still pass the various tests that you have written if not then you caught something.

Is this example simple enough. something that came to my mind immediately.

Your app might be responsible for calcultaing the permutation and combination of somethings or a simple calculator for that matter.

Bonus: a ppt that I found sometime back that I shared with a colleague: http://www.slideshare.net/dhelper/real-life-unit-testing

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜