Note that there are some explanatory texts on larger screens.

plurals
  1. POUnit Testing Multiple Levels Of Exceptions -- Where To Stop?
    primarykey
    data
    text
    <p>Let's pretend I have 3 classes that each have exactly one responsibly (and method). Let's also pretend that these classes have interfaces to facilitate dependency injection. Class A calls the interface for class B and class B calls the interface for class C. If class C throws a NotAPrimeNumberException (if say, the int parameter isn't a prime number), I would expect to have a unit test that makes sure that C throws an NotAPrimeNumberException if the passed in parameter isn't a prime number. So far so good.</p> <p>I'm currently under the belief that the unit tests provide all of the documentation I need to understand the behavior of the method being tested. So the aforementioned unit test would be something like MakeSureNotAPrimeNumberExceptionIsThrownIfNumberisNotPrimeTest().</p> <p>Class B knows that class C can throw a NotAPrimeNumberException. If I want to let the NotAPrimeNumberException bubble up out of class B should I write a unit test for class B to somehow check that a NotAPrimeNumberException is thrown in some circumstances? What about Class A? If A also lets the NotAPrimeNumberException bubble up, should it also have a unit test for this?</p> <p>My concern is that if I DON'T write a unit test in Class B then the consumers for class B won't be aware that class B can throw this type of exception. However, if I DO write the unit test then it is a little silly that I have to force the call to class B to throw a NotAPrimeNumberException only to NOT handle the exception in class B. If I don't write a unit test, what is the appropriate way, if any, to document in the API that this exception can occur?</p> <p>The bonus question is how do you facilitate this in NUnit with Rhino-mocks? This is of course dependent upon the first two questions.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload