<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Best Practices, Mock Usage Pattern</title>
	<atom:link href="http://www.elilopian.com/2007/04/26/best-practices-mock-usage-pattern/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.elilopian.com/2007/04/26/best-practices-mock-usage-pattern/</link>
	<description>Creating better software</description>
	<lastBuildDate>Mon, 02 Jan 2012 09:09:26 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Eli Lopian</title>
		<link>http://www.elilopian.com/2007/04/26/best-practices-mock-usage-pattern/comment-page-1/#comment-792</link>
		<dc:creator>Eli Lopian</dc:creator>
		<pubDate>Sun, 29 Apr 2007 21:46:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.elilopian.com/2007/04/26/best-practices-mock-usage-pattern/#comment-792</guid>
		<description>Ian,
There are a few reasons to put Verify in the test method:
1. In those cases where the test throws some kind of exception. The TearDown will run a Verify and you will see many failures that will make it harder to find the real problem.
2. Since NUnit 2.2, all failures in the TearDown are ugly, with big call stacks making it harder to understand.

Note: There is no reason to call ClearAll right after Verify, because Verify clears all the mocks too. The reason that ClearAll is called in the TearDown are for those cases where the tests throws an exception.</description>
		<content:encoded><![CDATA[<p>Ian,<br />
There are a few reasons to put Verify in the test method:<br />
1. In those cases where the test throws some kind of exception. The TearDown will run a Verify and you will see many failures that will make it harder to find the real problem.<br />
2. Since NUnit 2.2, all failures in the TearDown are ugly, with big call stacks making it harder to understand.</p>
<p>Note: There is no reason to call ClearAll right after Verify, because Verify clears all the mocks too. The reason that ClearAll is called in the TearDown are for those cases where the tests throws an exception.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ian Davis</title>
		<link>http://www.elilopian.com/2007/04/26/best-practices-mock-usage-pattern/comment-page-1/#comment-711</link>
		<dc:creator>Ian Davis</dc:creator>
		<pubDate>Thu, 26 Apr 2007 11:04:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.elilopian.com/2007/04/26/best-practices-mock-usage-pattern/#comment-711</guid>
		<description>Is there any particular reason that you are calling Verify() in the test? I have defaulted (perhaps wrongly) to putting all of my mock management calls into the SetUp and TearDown methods. If a test is run that does not use mocking then I am out a small bit of performance, but it is handy. It also allows me to refactor my tests more easily. Below is what I try to start with when testing a class with mocks.

&lt;code&gt;
[TestFixture]
public class MyTests { 
        #region Setup/tear down

        [TestFixtureSetUp]
        public void InitTestFixture() {
        }

        [TestFixtureTearDown]
        public void CleanUpTestFixture() {
        }
        
        [SetUp]
        public void InitTest() {
            MockManager.Init();
        }

        [TearDown]
        public void CleanUpTest() {
            MockManager.Verify();
            MockManager.ClearAll();
        }

        #endregion
}
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Is there any particular reason that you are calling Verify() in the test? I have defaulted (perhaps wrongly) to putting all of my mock management calls into the SetUp and TearDown methods. If a test is run that does not use mocking then I am out a small bit of performance, but it is handy. It also allows me to refactor my tests more easily. Below is what I try to start with when testing a class with mocks.</p>
<p><code><br />
[TestFixture]<br />
public class MyTests {<br />
        #region Setup/tear down</p>
<p>        [TestFixtureSetUp]<br />
        public void InitTestFixture() {<br />
        }</p>
<p>        [TestFixtureTearDown]<br />
        public void CleanUpTestFixture() {<br />
        }</p>
<p>        [SetUp]<br />
        public void InitTest() {<br />
            MockManager.Init();<br />
        }</p>
<p>        [TearDown]<br />
        public void CleanUpTest() {<br />
            MockManager.Verify();<br />
            MockManager.ClearAll();<br />
        }</p>
<p>        #endregion<br />
}<br />
</code></p>
]]></content:encoded>
	</item>
</channel>
</rss>

