Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Would be great if you can have some code samples. BUT, as I understood you question, you are <a href="http://en.wikipedia.org/wiki/Unit_testing" rel="nofollow">Unit Testing</a> a method, and it will throw an exception immediately after checking some kind of a business rule. You also have dependencies injected to this class (SUT - System Under Test). Those dependencies are mocked/stubbed in your Unit Test, but because of the exception being thrown immediately, you are not sure that mocking everything is a good idea or not.</p> <p>Typically, with any Unit Test, you want to be absolutely sure that your Unit Test only contains what it needs, but nothing else. If you are mocking stubbing stuff in your Unit Test and they have not been used during your Test execution within your SUT, then</p> <p>a. Your Tests can be harder to maintain, and harder to read as it may not be easy to figure it out what the test has really being used and what the test is actually doing.</p> <p>b. Your Test can fail for the wrong reason. For example, your SUT works exactly the way you expect to work, but because of unwanted dependencies is being mocked, any refactoring and fail your test for the wrong reason. This is also called <a href="http://xunitpatterns.com/false%20positive.html" rel="nofollow">false positive</a> test.</p> <p>What you should try to achieve is to write a separate Unit Test to verify the exception scenario. This test would only have the dependencies injected to make your rule violate so you can test the exception scenario. All your other tests would have dependencies injected to accordingly to make those tests satisfy as possible.</p>
 

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