<?xml version="1.0" encoding="windows-1252"?>
<node id="158417" title="Re: The Joy of Test" created="2002-04-11 16:08:57" updated="2005-07-27 16:51:50">
<type id="11">
note</type>
<author id="22308">
dws</author>
<data>
<field name="doctext">
First, congrats on taking the Testing plunge.
&lt;p&gt;
&lt;i&gt;Some of my tests are dependant on the internals and I dither on whether or not that's a good thing, ...&lt;/i&gt;
&lt;p&gt;
The XP folks call this "code smell". It's a signal that some restructuring or refactoring is needed in the code.
&lt;p&gt;
This happens to me a lot when I build &lt;i&gt;post facto&lt;/i&gt; test cases, and find that a class is too dependent on, for example, there being a database underneath it, which can make it cumbersome to test. A solution to that particular problem is to restructure a class to make use a "database interface" class that can be passed in either at object creating time or to a method that populates an instance of the object. This makes it easy to swap in a "dummy" (testing) database interface during testing. This change takes code that looks like:
&lt;code&gt;  $calendar-&gt;loadFromDatabase();
&lt;/code&gt;
and reworks it to look like
&lt;code&gt;  $calendar-&gt;loadFrom($calendarDatabase);
&lt;/code&gt;
where $calendarDatase is either a wrapper class that sits atop some "real" database, or an instance of TestCalendarDatabase, which exists soley to provide reproducable testing data.
&lt;p&gt;
</field>
<field name="root_node">
158399</field>
<field name="parent_node">
158399</field>
</data>
</node>
