Pat.<br><br>I&#39;m going to reply by promising to reply. You&#39;ve asked a
ton of really useful and insightful questions. I can&#39;t do them justice
without sitting down and spending a bunch of time thinking about them.
<br><br>I&#39;m going to be off the radar for a bit over Christmas - I&#39;ve
had an insane year and I&#39;ve promised myself (and my wife) some quiet
time. Your questions have a little star next to them in my gmail inbox,
which means at the very least they&#39;ll be ignored less than the other
mail I have to respond to :)
<br><br>The one sentence response, though, is that I honestly don&#39;t know (which is why I need to think about it). I can tell you I <i>think</i> I isolate services from their dependencies using mocks, I <i>think</i>
I never stub domain objects (I definitely never mock them, but stubbing
them is different), I can&#39;t say how I test layers because I think we
have a different definition of layers.
<br><br>The reason I&#39;m being being so vague is that I usually specify
behaviour from the outside in, starting with the &quot;outermost&quot; objects
(the ones that appear in the scenario steps) and working inwards as I
implement each bit of behaviour. That way I discover service
dependencies that I introduce as mocks, and other domain objects that
become, well, domain objects. Then there are other little classes that
fall out of the mix that seem to make sense as I go along. I don&#39;t
usually start out with much more of a strategy than that. I can&#39;t speak
as a tester because I&#39;m not one, so I can&#39;t really give you a sensible
answer for how isolated my tests are. I simply don&#39;t have tests at that
level. At an acceptance level my scenarios only ever use real objects
wired together doing full end-to-end testing. Sometimes I&#39;ll swap in a
lighter-weight implementation (say using an in-memory database rather
than a remote one, or an in-thread Java web container like Jetty rather
than firing up Tomcat), but all the wiring is still the same (say JDBC
or HTTP-over-the-wire).
I&#39;m still not entirely sure how this maps to Rails, but in Java MVC web apps I would <i>want</i> the controller examples failing if the model&#39;s behaviour changed in a particular way, so I can&#39;t think of a reason why I would want fake domain objects.
<br><br>Like I said, I&#39;ll have a proper think and get back to you.<br><br>Cheers,<br><font color="#888888">Dan</font><br><br><div class="gmail_quote">On Dec 15, 2007 7:17 AM, Pat Maddox &lt;<a href="mailto:pergesu@gmail.com">
pergesu@gmail.com</a>&gt; wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div class="Ih2E3d">On Dec 8, 2007 4:06 AM, Dan North &lt;
<a href="mailto:tastapod@gmail.com">tastapod@gmail.com</a>&gt; wrote:<br>&gt; I prefer the mantra &quot;mock roles, not objects&quot;, in other words, mock things<br>&gt; that have behaviour (services, components, resources, whatever your
<br>&gt; preferred term is) rather than stubbing out domain objects themselves. If<br>&gt; you have to mock domain objects it&#39;s usually a smell that your domain<br>&gt; implementation is too tightly coupled to some infrastructure.
<br><br></div>Assuming you could easily write Rails specs using the real domain<br>objects, but not hit the database, would you &quot;never&quot; mock domain<br>objects (where &quot;never&quot; means you deviate only in extraordinary
<br>circumstances)? &nbsp;I&#39;m mostly curious in the interaction between<br>controller and model...if you use real models, then changes to the<br>model code could very well lead to failing controller specs, even<br>though the controller&#39;s logic is still correct.
<br><br>What is your opinion on isolating tests? &nbsp;Do you try to test each<br>class in complete isolation, mocking its collaborators? &nbsp;When you use<br>interaction-based tests, do you always leave those in place, or do you<br>
substitute real objects as you implement them (and if so, do your<br>changes move to a more state-based style)? &nbsp;How do you approach<br>specifying different layers within an app? &nbsp;Do you use real<br>implementations if there are lightweight ones available, or do you
<br>mock everything out?<br><br>I realize that&#39;s a ton of questions...I&#39;d be very grateful (and<br>impressed!) if you took the time to answer any of them. &nbsp;Also I&#39;d love<br>to hear input from other people as well.
<br><font color="#888888"><br>Pat<br></font></blockquote></div><br>