This is the class I'm a little worried about. My goal is a unit test address list:
public class LabelPrinter { private readonly IEnumerable<Address> _addresses; public LabelPrinter(IEnumerable<Address> addresses) { _addresses = addresses; } public Document Create() { // ... Generate PDF, etc ... } }
So what is better:
, , , , - . , , , , .
, . , , . , , , - .
- Address, , LabelPrinter. , , .
Address
LabelPrinter
addresses? , , , . , , , :
addresses
[Test] public void Test() { IEnumerable<Address> addresses = new List<Address>(); LabelPrinter printer = new LabelPrinter(addresses); ... // execute your test here Assert.AreEqual(blah, addresses.get(0)); // or any other assertion you want to make on the addresses list // created up above. }
, . 2.
A test Create, not a setter (which is effective because you are here). I believe that testing setters / getters will be a bit of a waste of time. Especially since most of the time, the setter must be performed to perform some other test. They are also for the most part too simple to fail.
Create
Therefore, instead of confirming that it LabelPrinterhas _addresses, and this is Y, check that the output Createcontains the relevant data.
_addresses