Pergunta

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.

Foi útil?

Solução

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

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top