<?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: Unit Testing with Stubs and Mocks</title>
	<atom:link href="http://blog.springsource.org/2007/01/15/unit-testing-with-stubs-and-mocks/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.springsource.org/2007/01/15/unit-testing-with-stubs-and-mocks/</link>
	<description>The voice of SpringSource</description>
	<lastBuildDate>Wed, 08 Feb 2012 17:31:53 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.1</generator>
	<item>
		<title>By: Tests Easy &#124; Fusion Living</title>
		<link>http://blog.springsource.org/2007/01/15/unit-testing-with-stubs-and-mocks/comment-page-1/#comment-204489</link>
		<dc:creator>Tests Easy &#124; Fusion Living</dc:creator>
		<pubDate>Wed, 05 Oct 2011 10:47:02 +0000</pubDate>
		<guid isPermaLink="false">http://blog.interface21.com/main/2007/01/15/unit-testing-with-stubs-and-mocks/#comment-204489</guid>
		<description>[...] Easy, 100[/phpbay] HIV Test – Easy &amp; ConfidentialWhat type of test is there for HIV? The actual test name for determi... 3 months of exposure to HIV, using the screening test (repeated Elisa). If the screening test [...]</description>
		<content:encoded><![CDATA[<p>[...] Easy, 100[/phpbay] HIV Test – Easy &amp; ConfidentialWhat type of test is there for HIV? The actual test name for determi&#8230; 3 months of exposure to HIV, using the screening test (repeated Elisa). If the screening test [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Unit Testing</title>
		<link>http://blog.springsource.org/2007/01/15/unit-testing-with-stubs-and-mocks/comment-page-1/#comment-174613</link>
		<dc:creator>Unit Testing</dc:creator>
		<pubDate>Wed, 28 Jul 2010 12:58:40 +0000</pubDate>
		<guid isPermaLink="false">http://blog.interface21.com/main/2007/01/15/unit-testing-with-stubs-and-mocks/#comment-174613</guid>
		<description>I am a regular reader of this blog and the information here i get is unique and useful both. This information really help me in making my Unit Testing work far and far better then past.</description>
		<content:encoded><![CDATA[<p>I am a regular reader of this blog and the information here i get is unique and useful both. This information really help me in making my Unit Testing work far and far better then past.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dave Syer</title>
		<link>http://blog.springsource.org/2007/01/15/unit-testing-with-stubs-and-mocks/comment-page-1/#comment-104813</link>
		<dc:creator>Dave Syer</dc:creator>
		<pubDate>Wed, 30 Apr 2008 11:43:27 +0000</pubDate>
		<guid isPermaLink="false">http://blog.interface21.com/main/2007/01/15/unit-testing-with-stubs-and-mocks/#comment-104813</guid>
		<description>I think it sounds like you are thinking on the right lines, and all your concerns are valid.  Stubs have their place, but sharing stubs across unit tests (your example of components A and B above) does not scale, precisely because of the brittleness you are worried about.  I always define stubs as inner classes in the test that needs them - make them private and that way no-one can be tempted to share it and introduce an implicit dependency.  The &quot;test data&quot; then gets maintained by the unit test owner, and there is no need to worry about it as a separate category of data.  Base classes with empty methods are helpful to avoid cluttering up tests with implementations of many methods that aren&#039;t used.</description>
		<content:encoded><![CDATA[<p>I think it sounds like you are thinking on the right lines, and all your concerns are valid.  Stubs have their place, but sharing stubs across unit tests (your example of components A and B above) does not scale, precisely because of the brittleness you are worried about.  I always define stubs as inner classes in the test that needs them &#8211; make them private and that way no-one can be tempted to share it and introduce an implicit dependency.  The &#034;test data&#034; then gets maintained by the unit test owner, and there is no need to worry about it as a separate category of data.  Base classes with empty methods are helpful to avoid cluttering up tests with implementations of many methods that aren&#039;t used.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: KV</title>
		<link>http://blog.springsource.org/2007/01/15/unit-testing-with-stubs-and-mocks/comment-page-1/#comment-104762</link>
		<dc:creator>KV</dc:creator>
		<pubDate>Tue, 29 Apr 2008 23:19:46 +0000</pubDate>
		<guid isPermaLink="false">http://blog.interface21.com/main/2007/01/15/unit-testing-with-stubs-and-mocks/#comment-104762</guid>
		<description>In our business group we are trying to embrace UNIT testing and doing our best to achieve a decent code coverage. However we are facing some interesting challenges. Initially we decided on the path of using stub data for Unit Testing (DB Unit is out of question at this point due to DB related constraints) and one of the challenges seems to be around creation and ongoing maintenance of test data. So here is a simple scenario

     Lets say there are two components that make our simple system - Component A and Component B. Component A depends on Component B. From unit testing perspective, comp B developer has created a robust set of &quot;stub&quot; data to meet his testing needs. Since Component A collaborates with B, the developer who is authoring A wants to leverage the test data already written for B. Now this introduces data dependency because the unique id(s) &amp; data used to drive B is now needed by A. This means &#039;A&#039; and &#039;B&#039; developer need to sit and talk about Data before they can author unit test cases. While this model might work when things are simple, some of us are asking questions like - will it scale? etc

That&#039;s said, if you could provide your thoughts, opinions, help for the following questions, it would help us move in the right direction

What is your opinion on using stub data for Unit Testing? 
Is this the way to go or are there other better ways? 
Does the stub based approach scale well when there are many components, developers etc (including offshore)
Is this just too brittle where the maintenance of test cases/data could become a chore?
Will this just introduce &quot;communication &amp; coordination&quot; complexities?
Should we think about a interaction-based testing (mocks) instead of state-based testing (stub)
If so, any pit falls with this approach</description>
		<content:encoded><![CDATA[<p>In our business group we are trying to embrace UNIT testing and doing our best to achieve a decent code coverage. However we are facing some interesting challenges. Initially we decided on the path of using stub data for Unit Testing (DB Unit is out of question at this point due to DB related constraints) and one of the challenges seems to be around creation and ongoing maintenance of test data. So here is a simple scenario</p>
<p>     Lets say there are two components that make our simple system &#8211; Component A and Component B. Component A depends on Component B. From unit testing perspective, comp B developer has created a robust set of &#034;stub&#034; data to meet his testing needs. Since Component A collaborates with B, the developer who is authoring A wants to leverage the test data already written for B. Now this introduces data dependency because the unique id(s) &amp; data used to drive B is now needed by A. This means &#039;A&#039; and &#039;B&#039; developer need to sit and talk about Data before they can author unit test cases. While this model might work when things are simple, some of us are asking questions like &#8211; will it scale? etc</p>
<p>That&#039;s said, if you could provide your thoughts, opinions, help for the following questions, it would help us move in the right direction</p>
<p>What is your opinion on using stub data for Unit Testing?<br />
Is this the way to go or are there other better ways?<br />
Does the stub based approach scale well when there are many components, developers etc (including offshore)<br />
Is this just too brittle where the maintenance of test cases/data could become a chore?<br />
Will this just introduce &#034;communication &amp; coordination&#034; complexities?<br />
Should we think about a interaction-based testing (mocks) instead of state-based testing (stub)<br />
If so, any pit falls with this approach</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Zuber</title>
		<link>http://blog.springsource.org/2007/01/15/unit-testing-with-stubs-and-mocks/comment-page-1/#comment-100445</link>
		<dc:creator>Zuber</dc:creator>
		<pubDate>Tue, 11 Mar 2008 16:15:23 +0000</pubDate>
		<guid isPermaLink="false">http://blog.interface21.com/main/2007/01/15/unit-testing-with-stubs-and-mocks/#comment-100445</guid>
		<description>Colin, Why do we write java classes for Unit Testing? 

So far there are lot of unit testing frameworks available today to choose from. Each stands with different approach.
But the matter of fact is, we still need to code. Can we not configure beans what we want to test and actual and expected results? 

Imagine a world where we write unit tests, if it&#039;s not so complex, in xml instead of creating lot of classes.

So here is an idea for a framework where you write your unit test cases in xml and not create any classes. 
The framework provides a helpers/wrappers around various unit frameworks like Junit, TestNG, Jmock etc. 
It reads the definition of test case  and data providers and generates TestCase using any of above specified Unit Testing frameworks and executes it. We can even set-up some callback mechanism for better control over automated behavior.

Your thoughts.</description>
		<content:encoded><![CDATA[<p>Colin, Why do we write java classes for Unit Testing? </p>
<p>So far there are lot of unit testing frameworks available today to choose from. Each stands with different approach.<br />
But the matter of fact is, we still need to code. Can we not configure beans what we want to test and actual and expected results? </p>
<p>Imagine a world where we write unit tests, if it&#039;s not so complex, in xml instead of creating lot of classes.</p>
<p>So here is an idea for a framework where you write your unit test cases in xml and not create any classes.<br />
The framework provides a helpers/wrappers around various unit frameworks like Junit, TestNG, Jmock etc.<br />
It reads the definition of test case  and data providers and generates TestCase using any of above specified Unit Testing frameworks and executes it. We can even set-up some callback mechanism for better control over automated behavior.</p>
<p>Your thoughts.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Screenedtwenty</title>
		<link>http://blog.springsource.org/2007/01/15/unit-testing-with-stubs-and-mocks/comment-page-1/#comment-23608</link>
		<dc:creator>Screenedtwenty</dc:creator>
		<pubDate>Sat, 19 May 2007 00:23:32 +0000</pubDate>
		<guid isPermaLink="false">http://blog.interface21.com/main/2007/01/15/unit-testing-with-stubs-and-mocks/#comment-23608</guid>
		<description>For anyone interested in more reading on Unit Testing, this may or may not answer more questions: http://www.coderslog.com/Unit_Testing_101

We might also be getting usage examples in the future in a separate article.

Thank you for your time.</description>
		<content:encoded><![CDATA[<p>For anyone interested in more reading on Unit Testing, this may or may not answer more questions: <a href="http://www.coderslog.com/Unit_Testing_101" rel="nofollow">http://www.coderslog.com/Unit_Testing_101</a></p>
<p>We might also be getting usage examples in the future in a separate article.</p>
<p>Thank you for your time.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tim</title>
		<link>http://blog.springsource.org/2007/01/15/unit-testing-with-stubs-and-mocks/comment-page-1/#comment-9145</link>
		<dc:creator>Tim</dc:creator>
		<pubDate>Wed, 24 Jan 2007 17:37:38 +0000</pubDate>
		<guid isPermaLink="false">http://blog.interface21.com/main/2007/01/15/unit-testing-with-stubs-and-mocks/#comment-9145</guid>
		<description>As a jMock fan, I figured I&#039;d post an example of the same test with jMock.
Assumes your test extends MockObjectTestCase

    public void testActiveWhenCollaboratorIsActive() {
        // Normally done in setUp
        SimpleService service = new SimpleService();
        Mock collaborator = mock(Collaborator.class);
        service.setCollaborator((Collaborator) collaborator.proxy());

        // Actual test
        collaborator.expects(once()).method(&quot;isActive&quot;).will(returnValue(true));
        assertTrue(service.isActive());
    }</description>
		<content:encoded><![CDATA[<p>As a jMock fan, I figured I&#039;d post an example of the same test with jMock.<br />
Assumes your test extends MockObjectTestCase</p>
<p>    public void testActiveWhenCollaboratorIsActive() {<br />
        // Normally done in setUp<br />
        SimpleService service = new SimpleService();<br />
        Mock collaborator = mock(Collaborator.class);<br />
        service.setCollaborator((Collaborator) collaborator.proxy());</p>
<p>        // Actual test<br />
        collaborator.expects(once()).method(&#034;isActive&#034;).will(returnValue(true));<br />
        assertTrue(service.isActive());<br />
    }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: deployJava &#187; Unit Testing with Stubs and Mocks</title>
		<link>http://blog.springsource.org/2007/01/15/unit-testing-with-stubs-and-mocks/comment-page-1/#comment-8995</link>
		<dc:creator>deployJava &#187; Unit Testing with Stubs and Mocks</dc:creator>
		<pubDate>Mon, 22 Jan 2007 15:14:18 +0000</pubDate>
		<guid isPermaLink="false">http://blog.interface21.com/main/2007/01/15/unit-testing-with-stubs-and-mocks/#comment-8995</guid>
		<description>[...] Go&#8230; [...]</description>
		<content:encoded><![CDATA[<p>[...] Go&#8230; [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: redsolo</title>
		<link>http://blog.springsource.org/2007/01/15/unit-testing-with-stubs-and-mocks/comment-page-1/#comment-8480</link>
		<dc:creator>redsolo</dc:creator>
		<pubDate>Wed, 17 Jan 2007 08:12:05 +0000</pubDate>
		<guid isPermaLink="false">http://blog.interface21.com/main/2007/01/15/unit-testing-with-stubs-and-mocks/#comment-8480</guid>
		<description>The best description of mocks/stubs/fakes/etc are available at Martin Fowlers http://www.martinfowler.com/articles/mocksArentStubs.html. He has a very good indepth explaination when to use mocks and when to use stubs. Mocks enforces another type of testing, a sort of behaviourtesting than what is normal with unit testing.</description>
		<content:encoded><![CDATA[<p>The best description of mocks/stubs/fakes/etc are available at Martin Fowlers <a href="http://www.martinfowler.com/articles/mocksArentStubs.html" rel="nofollow">http://www.martinfowler.com/articles/mocksArentStubs.html</a>. He has a very good indepth explaination when to use mocks and when to use stubs. Mocks enforces another type of testing, a sort of behaviourtesting than what is normal with unit testing.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Colin Yates</title>
		<link>http://blog.springsource.org/2007/01/15/unit-testing-with-stubs-and-mocks/comment-page-1/#comment-8408</link>
		<dc:creator>Colin Yates</dc:creator>
		<pubDate>Tue, 16 Jan 2007 12:31:33 +0000</pubDate>
		<guid isPermaLink="false">http://blog.interface21.com/main/2007/01/15/unit-testing-with-stubs-and-mocks/#comment-8408</guid>
		<description>Nice article Dave.

I tend to prefer dynamic mocks simply because when doing TDD you don&#039;t always know the full API of the collaborator.  If you are using stubs, this results in the horrible situation of having to go through unrelated tests and adding/removing/changing methods every time you change the API of a collaborator (add a new method etc.).

This isn&#039;t a problem with mocks because you only describe the bits that you are using...if a new method is added to the collaborator, who cares :)

Mocks also (IMO) lead to much more readable code as well, they also allow you to define the behaviour of multiple calls to the same method.  Of course this can be done using stubs, but the code is much more complex.

Nice article.</description>
		<content:encoded><![CDATA[<p>Nice article Dave.</p>
<p>I tend to prefer dynamic mocks simply because when doing TDD you don&#039;t always know the full API of the collaborator.  If you are using stubs, this results in the horrible situation of having to go through unrelated tests and adding/removing/changing methods every time you change the API of a collaborator (add a new method etc.).</p>
<p>This isn&#039;t a problem with mocks because you only describe the bits that you are using&#8230;if a new method is added to the collaborator, who cares <img src='http://blog.springsource.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Mocks also (IMO) lead to much more readable code as well, they also allow you to define the behaviour of multiple calls to the same method.  Of course this can be done using stubs, but the code is much more complex.</p>
<p>Nice article.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

