<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>marthijn. &#187; Testing</title>
	<atom:link href="http://www.marthijnvandenheuvel.com/category/development/testing/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.marthijnvandenheuvel.com</link>
	<description></description>
	<lastBuildDate>Fri, 30 Dec 2011 13:03:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Using NUnit in Visual Studio 2010</title>
		<link>http://www.marthijnvandenheuvel.com/2010/06/09/using-nunit-in-visual-studio-2010/</link>
		<comments>http://www.marthijnvandenheuvel.com/2010/06/09/using-nunit-in-visual-studio-2010/#comments</comments>
		<pubDate>Wed, 09 Jun 2010 12:13:10 +0000</pubDate>
		<dc:creator>Marthijn</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[.NET 4.0]]></category>
		<category><![CDATA[NUnit]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://www.marthijnvandenheuvel.com/?p=196</guid>
		<description><![CDATA[How to use NUnit in Visual Studio 2010.]]></description>
			<content:encoded><![CDATA[<p>Like in older versions of <a href="http://www.microsoft.com/visualstudio" target="_blank">Visual Studio</a> it is possible to use <a href="http://www.nunit.org" target="_blank">NUnit</a> as an external tool in the new 2010 version. By creating a toolbar as well it is very easy to run your test suite. The usual way to add an external command is by clicking the menu Tools -&gt; External Tools. However, by default this menu item is not visible. To enable this menu item go to Tools -&gt; Settings -&gt; Expert Settings.</p>
<p><a href="http://www.marthijnvandenheuvel.com/wp-content/uploads/2010/06/vs2010.png" rel="lightbox[196]"><img class="aligncenter size-full wp-image-197" title="Visual Studio 2010" src="http://www.marthijnvandenheuvel.com/wp-content/uploads/2010/06/vs2010.png" alt="Visual Studio 2010" width="214" height="32" /></a></p>
<p><span id="more-196"></span></p>
<p>The first step is download and install the latest version of NUnit since older versions are not compatible with .NET 4. NUnit version 2.5.5 can be downloaded <a href="http://www.nunit.org/?p=download" target="_blank">here</a>.</p>
<p>Now go to Tools -&gt; External Tools:</p>
<p><a href="http://www.marthijnvandenheuvel.com/wp-content/uploads/2010/06/vs2010_exttools.png" rel="lightbox[196]"><img class="aligncenter size-full wp-image-198" title="Visual Studio 2010 External Tools" src="http://www.marthijnvandenheuvel.com/wp-content/uploads/2010/06/vs2010_exttools.png" alt="Visual Studio 2010 External Tools" width="493" height="481" /></a></p>
<p>I think this screen shot explains itself very well. Now its possible to add this external command to a tool bar. To do so go to View -&gt; Toolbars -&gt; Customize:</p>
<p><a href="http://www.marthijnvandenheuvel.com/wp-content/uploads/2010/06/vs2010_customize.png" rel="lightbox[196]"><img class="aligncenter size-full wp-image-200" title="Visual Studio 2010 Customize Toolbars" src="http://www.marthijnvandenheuvel.com/wp-content/uploads/2010/06/vs2010_customize.png" alt="Visual Studio 2010 Customize Toolbars" width="465" height="509" /></a></p>
<p>Press the New button and enter a name. Now open the Commands tab and add the external command (usually External Command 1 when you don&#8217;t have any other external commands) to the toolbar:</p>
<p style="text-align: center;"><a href="http://www.marthijnvandenheuvel.com/wp-content/uploads/2010/06/vs2010_customize2.png" rel="lightbox[196]"><img class="aligncenter size-full wp-image-202" title="Visual Studio 2010 Commands" src="http://www.marthijnvandenheuvel.com/wp-content/uploads/2010/06/vs2010_customize2.png" alt="Visual Studio 2010 Toolbars" width="801" height="529" /></a></p>
<p style="text-align: left;">When clicking the NUnit button in the new toolbar the NUnit GUI starts and loads your test suite.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.marthijnvandenheuvel.com/2010/06/09/using-nunit-in-visual-studio-2010/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Unit testing in Watir</title>
		<link>http://www.marthijnvandenheuvel.com/2010/04/14/unit-testing-in-watir/</link>
		<comments>http://www.marthijnvandenheuvel.com/2010/04/14/unit-testing-in-watir/#comments</comments>
		<pubDate>Wed, 14 Apr 2010 15:17:12 +0000</pubDate>
		<dc:creator>Marthijn</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Watir]]></category>

		<guid isPermaLink="false">http://www.marthijnvandenheuvel.com/?p=149</guid>
		<description><![CDATA[Write a simple unit test in Watir]]></description>
			<content:encoded><![CDATA[<p><a href="http://watir.com/" target="_blank">Watir</a> is an open-source Ruby library for automating web browsers. Combined with unit testing for Ruby it is a really powerful tool to test websites and webapplications. In this post I explain how to write a test for a simple website.</p>
<div id="attachment_150" class="wp-caption aligncenter" style="width: 120px"><a href="http://www.marthijnvandenheuvel.com/wp-content/uploads/2010/04/watir.png" rel="lightbox[149]"><img class="size-full wp-image-150" title="Watir" src="http://www.marthijnvandenheuvel.com/wp-content/uploads/2010/04/watir.png" alt="Watir" width="110" height="103" /></a><p class="wp-caption-text">Watir</p></div>
<p><span id="more-149"></span></p>
<p>First download and install <a href="http://www.ruby-lang.org/en/downloads/" target="_blank">Ruby</a>. If you are familiar with <a href="http://www.eclipse.org/" target="_blank">Eclipse</a>, <a href="http://www.aptana.com/" target="_blank">Aptana</a> is a nice web development plugin (see <a href="http://osdir.com/ml/RubyonRailsTalk/2009-08/msg02136.html" target="_blank">this simple installation tutorial</a>). If you don&#8217;t know how to use Ruby, <a href="http://www.basvandijk.eu/" target="_blank">Bas</a> has a <a href="http://www.basvandijk.eu/2010/03/28/getting-started-with-ruby/" target="_blank">nice article</a> about getting started with Ruby.</p>
<p>The second step is <a href="http://watir.com/installation/" target="_blank">install Watir</a>. You can try <a href="http://watir.com/examples/" target="_blank">these examples</a> to see what Watir does.</p>
<h2>Testing a simple website</h2>
<p>For one of my school projects I had to write a simple test for one of the function of this <a href="http://www.calcenstein.com/" target="_blank">online calculator</a>. In this tutorial we will test the <a href="http://www.calcenstein.com/calc/0416.php" target="_blank">GCF and LCM function</a>. Start with creating a new Ruby script containing the right requirements and a test case class:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'watir'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'test/unit'</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> TC_LCM_GCD <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#CC00FF; font-weight:bold;"><span style="color:#6666ff; font-weight:bold;">Test::Unit::TestCase</span></span>
 <span style="color:#9966CC; font-weight:bold;">def</span> test_lcm_gcd
  <span style="color:#008000; font-style:italic;"># ...</span>
 <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>In order to let Watir start a new browser add the following to the test_lcm_gcd function:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#6666ff; font-weight:bold;">Watir::Browser</span>.<span style="color:#9900CC;">default</span> = <span style="color:#996600;">&quot;ie&quot;</span>
b = <span style="color:#6666ff; font-weight:bold;">Watir::Browser</span>.<span style="color:#9900CC;">start</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;http://www.calcenstein.com/calc/0416.php&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#008000; font-style:italic;"># GCF and LCM</span></pre></div></div>

<p>If you want to use Firefox for testing, change &#8220;ie&#8221; to &#8220;firefox&#8221; and don&#8217;t forget to install the <a href="http://watir.com/installation/" target="_blank">plugin</a>. The second line starts a new browser window.</p>
<p>Our goal is to let Watir insert two values (the &#8216;First Value&#8217; and &#8216;Second Value&#8217; input field), and then press the &#8216;Solve&#8217; button. In order to do so we need to know the name or id (or value in some cases) of the input fields and the &#8216;Solve&#8217; button. Instead of looking at the source I can recommend to use the <a href="https://addons.mozilla.org/nl/firefox/addon/1843" target="_blank">Firebug</a> add-on for Firefox, and use the inspect function. The &#8216;First Value&#8217; input is named &#8216;a&#8217;, and the &#8216;Second Value&#8217; input is named &#8216;b&#8217;. We want to set &#8216;a&#8217; to 30 and &#8216;b&#8217; to 45:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">b.<span style="color:#9900CC;">text_field</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:name</span>, <span style="color:#996600;">&quot;a&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">set</span> <span style="color:#996600;">&quot;30&quot;</span>
b.<span style="color:#9900CC;">text_field</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:name</span>, <span style="color:#996600;">&quot;b&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">set</span> <span style="color:#996600;">&quot;45&quot;</span></pre></div></div>

<p>When these values are set, Watir must press the &#8216;Solve&#8217; button. It appears this button doesn&#8217;t have a name or id, so get it by value and execute the click action:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">b.<span style="color:#9900CC;">button</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:value</span>, <span style="color:#996600;">&quot;Solve&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">click</span></pre></div></div>

<p>Now the click action is executed and the result is printed in the other two input fields (named &#8216;lcmA&#8217; and &#8216;gcdA&#8217;). Like in all other test cases, the result must be verified. The correct result is LCM = 90 and GCF = 15, so use assertions to check the values:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">assert<span style="color:#006600; font-weight:bold;">&#40;</span>b.<span style="color:#9900CC;">text_field</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:name</span>, <span style="color:#996600;">&quot;lcmA&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">value</span> == <span style="color:#996600;">&quot;90&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
assert<span style="color:#006600; font-weight:bold;">&#40;</span>b.<span style="color:#9900CC;">text_field</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:name</span>, <span style="color:#996600;">&quot;gcdA&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">value</span> == <span style="color:#996600;">&quot;15&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>This simple test case is now complete. The test output should be something like this:</p>
<pre>Loaded suite My_test_suite
Started
.
Finished in 5.579 seconds.

1 tests, 2 assertions, 0 failures, 0 errors</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.marthijnvandenheuvel.com/2010/04/14/unit-testing-in-watir/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using Rhino Mocks to mock a void function</title>
		<link>http://www.marthijnvandenheuvel.com/2010/03/15/using-rhino-mocks-to-mock-a-void-function/</link>
		<comments>http://www.marthijnvandenheuvel.com/2010/03/15/using-rhino-mocks-to-mock-a-void-function/#comments</comments>
		<pubDate>Sun, 14 Mar 2010 23:01:57 +0000</pubDate>
		<dc:creator>Marthijn</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[NUnit]]></category>
		<category><![CDATA[Rhino Mocks]]></category>

		<guid isPermaLink="false">http://www.marthijnvandenheuvel.com/?p=95</guid>
		<description><![CDATA[Using NUnit and Rhino Mocks to create an expectation for a void function.]]></description>
			<content:encoded><![CDATA[<p>In some of my web applications I use <a href="http://www.ayende.com/projects/rhino-mocks.aspx" target="_blank">Rhino Mocks</a> to create mock objects. Usually the code has a record section where the expected calls are recorded, and a playback section where the testing is done. In the following code snippet the DoSomething() function calls a void function which is defined in the interface of _myMock. The problem is this void function is not expected and the <a href="http://www.nunit.org/index.php" target="_blank">NUnit</a> test run will fail:</p>
<pre>Rhino.Mocks.Exceptions.ExpectationViolationException : IMyInterface.MyVoidFunction; Expected #0, Actual #1.</pre>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008000;">&#40;</span>_mock<span style="color: #008000;">.</span><span style="color: #0000FF;">Record</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  Expect<span style="color: #008000;">.</span><span style="color: #0000FF;">Call</span><span style="color: #008000;">&#40;</span>_myMock<span style="color: #008000;">.</span><span style="color: #0000FF;">GetValue</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;a&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0600FF; font-weight: bold;">Return</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;b&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
  <span style="color: #008080; font-style: italic;">/* insert expectation for void function here */</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008000;">&#40;</span>_mock<span style="color: #008000;">.</span><span style="color: #0000FF;">Playback</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #008080; font-style: italic;">// DoSomething calls the mocked object's GetValue function, which returns 'b' when the parameter is 'a'</span>
  <span style="color: #008080; font-style: italic;">// DoSomething also calls a void function which is located in the interface of the mocked object, so this</span>
  <span style="color: #008080; font-style: italic;">// void function must be mocked too, else the test run will fail</span>
  Assert<span style="color: #008000;">.</span><span style="color: #0000FF;">AreEqual</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;b&quot;</span>, _myObject<span style="color: #008000;">.</span><span style="color: #0000FF;">DoSomething</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;a&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p><span id="more-95"></span></p>
<p>When trying to create an expectation for this void function Visual Studio will give a syntax error:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Expect<span style="color: #008000;">.</span><span style="color: #0000FF;">Call</span><span style="color: #008000;">&#40;</span>_myMock<span style="color: #008000;">.</span><span style="color: #0000FF;">MyVoidFunction</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// Argument '1': cannot convert from 'void' to 'Rhino.Mocks.Expect.Action'</span></pre></div></div>

<p>On the internet I found two solutions to fix this problem. The <a href="http://ayende.com/Blog/archive/2007/10/17/Rhino-Mocks-Void-methods-using-Expect.Call.aspx" target="_blank">first solution</a> uses a delegate:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Expect<span style="color: #008000;">.</span><span style="color: #0000FF;">Call</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">delegate</span><span style="color: #008000;">&#123;</span> _myMock<span style="color: #008000;">.</span><span style="color: #0000FF;">MyVoidFunction</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>The <a href="http://stackoverflow.com/questions/359831/rhinomock-test-mock-interface-void-functions" target="_blank">second solution</a> uses a <a href="http://msdn.microsoft.com/en-us/library/bb397687.aspx" target="_blank">lambda</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Expect<span style="color: #008000;">.</span><span style="color: #0000FF;">Call</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">=&gt;</span> _myMock<span style="color: #008000;">.</span><span style="color: #0000FF;">MyVoidFunction</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>Now the test will succeed.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.marthijnvandenheuvel.com/2010/03/15/using-rhino-mocks-to-mock-a-void-function/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

