Note that there are some explanatory texts on larger screens.

plurals
  1. USssmith
    primarykey
    data
    text
    plurals
    1. COAdding to last comment - if B is a third party or framework library, then you might write some "fixing" tests that document your assumptions about how it works, and then if/when you upgrade or replace B, you'll be informed by these tests if your assumptions about its behavior have changed. But the key point is that your unit tests should be testing your code, not the code your code depends on.
      singulars
    2. COIf B throws a NotAPrimeNumberException in response to a given parameter, then I would absolutely have a test for this in my suite of tests around B. I would not try and test B's behavior through a consumer of B (such as A, assuming A calls B). In A, I might test what A does if B throws an exception - that's testing A's behavior. I would not test, in A, that B actually does throw an exception under certain circumstances, as that is now testing B's behavior, not A's (and we have tests around B for that).
      singulars
    3. COYou answered your question with your comment. Your unit tests should document "all of the behavior of my method" and *not* the behavior of methods your method might call. As long as you're doing that, you're good. If it's important whether or how your method handles exceptions bubbling up to it, it's easy (using mocks or fakes) to set up a test where an exception is thrown to your method, and to verify it does the right thing with it. If that's important behavior, it seems valid to me as a unit test. But mock the interaction, don't rely on a particular other method implementation.
      singulars
 

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