Note that there are some explanatory texts on larger screens.

plurals
  1. POTDD test data loading methods
    primarykey
    data
    text
    <p>I am a TDD newb and I would like to figure out how to test the following code. </p> <p>I am trying to write my tests first, but I am having trouble for creating a test that touches my DataAccessor. I can't figure out how to fake it. I've done the extend the shipment class and override the Load() method; to continue testing the object. I feel as though I end up unit testing my Mock objects/stubs and not my real objects. I thought in TDD the unit tests were supposed to hit ALL of the methods on the object; however I can never seem to test that Load() code only the overriden Mock Load</p> <p>My tests were write an object that contains a list of orders based off of shipment number. </p> <p>I have an object that loads itself from the database.</p> <pre><code>public class Shipment { //member variables protected List&lt;string&gt; _listOfOrders = new List&lt;string&gt;(); protected string _id = "" //public properties public List&lt;string&gt; ListOrders { get{ return _listOfOrders; } } public Shipment(string id) { _id = id; Load(); } //PROBLEM METHOD // whenever I write code that needs this Shipment object, this method tries // to hit the DB and fubars my tests // the only way to get around is to have all my tests run on a fake Shipment object. protected void Load() { _listOfOrders = DataAccessor.GetOrders(_id); } } </code></pre> <p>I create my fake shipment class to test the rest of the classes methods .I can't ever test the Real load method without having an actual DB connection</p> <pre><code>public class FakeShipment : Shipment { protected new void Load() { _listOfOrders = new List&lt;string&gt;(); } } </code></pre> <p>Any thoughts? Please advise.</p> <p>Dave</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.
    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