Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Absolutely. The idea of unit tests is to ensure that changes do not affect behavior in unknown ways. You might save some time by not writing a test for <code>getFoo()</code>. If you change the type of <code>Foo</code> to be something a little more complex then you could easily forget to test the accessor. If you are questioning whether you should write a test or not, you are better off writing it.</p> <p>IMHO, if you are thinking about skipping adding tests for a method, you might want to ask yourself if the method is necessary or not. In interest of full disclosure, I am one of <em>those</em> people that only adds a setter or getter when it is proven necessary. You would be surprised how often you really don't need access to a specific member after construction or when you only want to give access to the result of some calculation that is really dependent on the member. But I digress.</p> <p>A good mantra is to always add tests. If you don't think that you need one because the method is trivial, consider removing the method instead. I realize that the common advice is that it is okay to skip tests for <em>"trivial"</em> methods but you have to ask yourself if the method is even necessary. If you skip the test, you are saying that the method will <strong>always</strong> be trivial. Remember that unit tests also function as documentation of the <em>intent</em> and the <em>contract</em> offered. Hence tests of a trivial method state that the method is indeed meant to be trivial.</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