<?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/"
	
	xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>igorbrejc.net &#187; Gallio and MbUnit</title>
	<atom:link href="http://igorbrejc.net/category/development/testing/gallio-and-mbunit/feed" rel="self" type="application/rss+xml" />
	<link>http://igorbrejc.net</link>
	<description>Just another developer's weblog</description>
	<lastBuildDate>Sun, 12 Feb 2012 06:47:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Web Testing &amp; Gallio: A Little Helpful Trick</title>
		<link>http://igorbrejc.net/development/continuous-integration/web-testing-gallio-a-little-helpful-trick</link>
		<comments>http://igorbrejc.net/development/continuous-integration/web-testing-gallio-a-little-helpful-trick#comments</comments>
		<pubDate>Mon, 18 Oct 2010 05:59:08 +0000</pubDate>
		<dc:creator>breki</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[continuous integration]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[Gallio and MbUnit]]></category>
		<category><![CDATA[Selenium]]></category>
		<category><![CDATA[snippets]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://igorbrejc.net/?p=1290</guid>
		<description><![CDATA[When doing automatic testing of Web apps using unit testing frameworks, it can be a pain in the butt to pinpoint the proper HTML element. A lot of times tests will fail because you used a wrong locator, but since the browser will automatically close after the test, you don’t have an access to the [...]]]></description>
			<content:encoded><![CDATA[<p>When doing automatic testing of Web apps using unit testing frameworks, it can be a pain in the butt to pinpoint the proper HTML element. A lot of times tests will fail because you used a wrong locator, but since the browser will automatically close after the test, you don’t have an access to the HTML code of the page to look at what’s actually there.</p>

<p>Fortunately Gallio provides a class called <strong>TestContext</strong> which contains the current information about the running test and which you can use to determine if the latest test is successful or not. This can then be used to run your custom handling code during the test teardown:</p>

<p>
<pre class="brush: csharp; title: ; notranslate">
        [TearDown]
        protected virtual void Teardown()
        {
            if (TestContext.CurrentContext.Outcome.Status == TestStatus.Failed)
            {
                using (TestLog.BeginSection(&quot;Failed web page HTML&quot;))
                    TestLog.Write(WebDriver.PageSource);
            }
        }
</pre></p>

<p>In the above snippet, we record the current Web page’s HTML code into Gallio’s log (the <strong>TestLog</strong> class). To avoid spamming the log, we do this for failed tests only. </p>

<p>Gallio provides a powerful framework which I think is very much underused, mostly because the documentation is not very detailed (to say the least).</p>
]]></content:encoded>
			<wfw:commentRss>http://igorbrejc.net/development/continuous-integration/web-testing-gallio-a-little-helpful-trick/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
	</item>
		<item>
		<title>Gallio: Starting And Stopping Selenium Server Automatically During Testing Using AssemblyFixture</title>
		<link>http://igorbrejc.net/development/cruisecontrolnet/gallio-starting-and-stopping-selenium-server-automatically-during-testing-using-assemblyfixture</link>
		<comments>http://igorbrejc.net/development/cruisecontrolnet/gallio-starting-and-stopping-selenium-server-automatically-during-testing-using-assemblyfixture#comments</comments>
		<pubDate>Tue, 16 Jun 2009 07:37:09 +0000</pubDate>
		<dc:creator>breki</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[continuous integration]]></category>
		<category><![CDATA[CruiseControl.NET]]></category>
		<category><![CDATA[Gallio and MbUnit]]></category>
		<category><![CDATA[Selenium]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://igorbrejc.net/development/continuous-integration/gallio-starting-and-stopping-selenium-server-automatically-during-testing-using-assemblyfixture</guid>
		<description><![CDATA[UPDATE (June 17th): I&#8217;ve updated the code, see the reasons for it at the end of the post. In previous projects I worked on we made sure the Selenium Java server was running by manually starting it on our machines (both developers&#8217; and build ones). This was cumbersome: restarting the build server meant we had [...]]]></description>
			<content:encoded><![CDATA[<p><strong>UPDATE (June 17th)</strong>: I&#8217;ve updated the code, see the reasons for it at the end of the post.</p>

<p>In previous projects I worked on we made sure the Selenium Java server was running by manually starting it on our machines (both developers&#8217; and build ones). This was cumbersome: restarting the build server meant we had to log on to the server after the reboot and run the Selenium server again. Of course, a lot of times we forgot to do this, which caused the build to fail.</p>

<p>This got me into thinking: is there a way in Gallio to specify some initialization (and cleanup) actions on the test assembly level? And of course, the answer is yes: using the <strong>AssemblyFixture</strong> attribute. This is what I like about Gallio/MbUnit: most of the time the feature requests I come up with are actually already implemented.</p>

<p>So anyway, you can specify this attribute on a class and then add <strong>FixtureSetUp</strong> and <strong>FixtureTearDown</strong> attributes on its methods. These will be executed on the test assembly-level: setup methods will be executed before any test fixtures have been run and teardown methods will be executed before the test assembly has been unloaded by the test runner.</p>

<p>I then used this nice feature to start the Selenium server and then dispose of it after tests:</p>

<div><pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, 'Courier New', courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">[AssemblyFixture]
<span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> SeleniumTestingSetup : IDisposable
{
    [FixtureSetUp]
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> Setup()
    {
        seleniumServerProcess = <span style="color: #0000ff">new</span> Process();
        seleniumServerProcess.StartInfo.FileName = <span style="color: #006080">"java"</span>;
        seleniumServerProcess.StartInfo.Arguments =
            <span style="color: #006080">"-jar ../../../lib/Selenium/selenium-server/selenium-server.jar -port 6371"</span>;
        seleniumServerProcess.Start();
    }

    <span style="color: #008000">/// &lt;summary&gt;</span>
    <span style="color: #008000">/// Performs application-defined tasks associated with freeing, releasing, or</span>
    <span style="color: #008000">/// resetting unmanaged resources.</span>
    <span style="color: #008000">/// &lt;/summary&gt;</span>
    <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> Dispose()
    {
        Dispose(<span style="color: #0000ff">true</span>);
        GC.SuppressFinalize(<span style="color: #0000ff">this</span>);
    }

    <span style="color: #008000">/// &lt;summary&gt;</span>
    <span style="color: #008000">/// Disposes the object.</span>
    <span style="color: #008000">/// &lt;/summary&gt;</span>
    <span style="color: #008000">/// &lt;param name="disposing"&gt;If &lt;code&gt;false&lt;/code&gt;, cleans up native resources. </span>
    <span style="color: #008000">/// If &lt;code&gt;true&lt;/code&gt; cleans up both managed and native resources&lt;/param&gt;</span>
    <span style="color: #0000ff">protected</span> <span style="color: #0000ff">virtual</span> <span style="color: #0000ff">void</span> Dispose(<span style="color: #0000ff">bool</span> disposing)
    {
        <span style="color: #0000ff">if</span> (<span style="color: #0000ff">false</span> == disposed)
        {
            <span style="color: #0000ff">if</span> (disposing)
                DisposeOfSeleniumServer();

            disposed = <span style="color: #0000ff">true</span>;
        }
    }

    <span style="color: #0000ff">private</span> <span style="color: #0000ff">void</span> DisposeOfSeleniumServer()
    {
        <span style="color: #0000ff">if</span> (seleniumServerProcess != <span style="color: #0000ff">null</span>)
        {
            <span style="color: #0000ff">try</span>
            {
                seleniumServerProcess.Kill();
                <span style="color: #0000ff">bool</span> result = seleniumServerProcess.WaitForExit(10000);
            }
            <span style="color: #0000ff">finally</span> 
            {
                seleniumServerProcess.Dispose();
                seleniumServerProcess = <span style="color: #0000ff">null</span>;
            }
        }
    }

    <span style="color: #0000ff">private</span> <span style="color: #0000ff">bool</span> disposed;
    <span style="color: #0000ff">private</span> Process seleniumServerProcess;
}</pre></div>

<p>Note that the class is <strong>disposable</strong> &#8211; this ensures the Selenium server is stopped even if you run tests in the debugger and then force the debugger to stop before finishing the work. The Dispose method calls DisposeOfSeleniumServer, which does the actual work of killing the process and disposing of the evidence.</p>

<p><strong>NOTE:</strong> This is a second version of the code. I needed to update the old one because I noticed that when running the tests in CruiseControl.NET, the Selenium server java process was not stopped properly. The only way I could stop it is by killing it, which in general isn&#8217;t a good practice. The unfortunate side effect of this &#8220;killing&#8221; is that the CruiseContol.NET service cannot be stopped normally &#8211; it also has to be killed when you need to restart it. I&#8217;ll try to solve this problem in the future.</p>
]]></content:encoded>
			<wfw:commentRss>http://igorbrejc.net/development/cruisecontrolnet/gallio-starting-and-stopping-selenium-server-automatically-during-testing-using-assemblyfixture/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
	</item>
		<item>
		<title>Gallio: Filter Attributes For Test Methods</title>
		<link>http://igorbrejc.net/development/continuous-integration/gallio-filter-attributes-for-test-methods</link>
		<comments>http://igorbrejc.net/development/continuous-integration/gallio-filter-attributes-for-test-methods#comments</comments>
		<pubDate>Mon, 08 Jun 2009 08:05:31 +0000</pubDate>
		<dc:creator>breki</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[continuous integration]]></category>
		<category><![CDATA[Gallio and MbUnit]]></category>
		<category><![CDATA[guidelines]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://igorbrejc.net/development/continuous-integration/gallio-filter-attributes-for-test-methods</guid>
		<description><![CDATA[There are three attributes which function as filters when running tests using any of the Gallio&#8217;s test runners: Pending: tests which are in development and currently don&#8217;t run should be marked with the Pending attribute. This means the test runner will skip them when running the build script. Ignore: this attribute is used for marking [...]]]></description>
			<content:encoded><![CDATA[<p>There are three attributes which function as filters when running tests using any of the Gallio&#8217;s test runners:</p>

<ul> <li><strong>Pending</strong>: tests which are in development and currently don&#8217;t run should be marked with the Pending attribute. This means the test runner will skip them when running the build script.  <li><strong>Ignore</strong>: this attribute is used for marking tests which are never to be run (they are kept in the code as a history). In general, it is a good practice to avoid such tests &#8211; you can get the history from your source control.  <li><strong>Explicit</strong>: tests marked with this attribute will only run when selected individually in the VS (Resharper, TestDriven.NET). They will not be run as part of the build script. Explicit tests are usually those which depend on a certain external system which cannot be guaranteed to be available at all times &#8211; we don&#8217;t want such tests to cause failures in our builds.</li></ul>

<p>It is a good practice to supply these attributes with a string argument describing the reasons for marking the test.</p>

<p>UPDATE: Jeff Brown kindly provided some additional information about these attributes:</p>

<blockquote> <p>Tests marked [Ignored] and [Pending] will show as Warning annotations in the test report in addition to being skipped. In ReSharper they will also be shown with a yellow warning stripe to remind you that they are there and need to be looked at.</p> <p>You can also add your own annotations to various code elements with the [Annotation] attribute.</p></blockquote>

<p>This is my first article in the &#8220;guidelines&#8221; series I plan to write in the future. I want to maintain these guidelines separate from concrete project&#8217;s documentation since in the past I always had to copy this kind of stuff from one project&#8217;s wiki to another.</p>
]]></content:encoded>
			<wfw:commentRss>http://igorbrejc.net/development/continuous-integration/gallio-filter-attributes-for-test-methods/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
	</item>
		<item>
		<title>Gallio: Running Tests In Parallel</title>
		<link>http://igorbrejc.net/development/continuous-integration/gallio-running-tests-in-parallel</link>
		<comments>http://igorbrejc.net/development/continuous-integration/gallio-running-tests-in-parallel#comments</comments>
		<pubDate>Fri, 16 Jan 2009 09:28:43 +0000</pubDate>
		<dc:creator>breki</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[continuous integration]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[Gallio and MbUnit]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://igorbrejc.net/?p=266</guid>
		<description><![CDATA[photo credit: Shahram Sharif Introduction Yesterday we finally managed to get our tests to run using our acceptance tests framework. I promise to write more about it some other time, but I&#8217;ll make a quick introduction now. First let&#8217;s start with the name of the framework: Accipio. The idea of Accipio is to specify acceptance [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.flickr.com/photos/14438701@N00/2423144088/" title="parallel" target="_blank"><img src="http://farm3.static.flickr.com/2368/2423144088_cb47aa7b45_m.jpg" alt="parallel" border="0" /></a><br /><small><a href="http://creativecommons.org/licenses/by/2.0/" title="Attribution License" target="_blank"><img src="http://igorbrejc.net/wp-content/plugins/photo-dropper/images/cc.png" alt="Creative Commons License" border="0" width="16" height="16" align="absmiddle" /></a> <a href="http://www.photodropper.com/photos/" target="_blank">photo</a> credit: <a href="http://www.flickr.com/photos/14438701@N00/2423144088/" title="Shahram Sharif" target="_blank">Shahram Sharif</a></small></p>

<h3>Introduction</h3>

<p>Yesterday we finally managed to get our tests to run using our acceptance tests framework. I promise to write more about it some other time, but I&#8217;ll make a quick introduction now.</p>

<p>First let&#8217;s start with the name of the framework: <strong>Accipio</strong>. The idea of Accipio is to specify acceptance tests in an XML form which is then automatically translated into MbUnit test code. I guess you can call it a lightweight FitNesse &#8211; there&#8217;s no Wiki, all test specifications are stored in XML files (which are then source-controlled). The XML is quite simple (you can see some initial brainstorming samples <a href="http://code.google.com/p/projectpilot/wiki/AutomatedAcceptanceTesting">here</a>).</p>

<p>But that&#8217;s not what I wanted to talk about now.</p>

<h3></h3>

<h3>Time Is Money, They Say</h3>

<p>While running the tests we determined that the whole test process took too long. We had around 100 test cases, each of which had to wait for 10 seconds after the initial action before it could assert the test conditions, which means at least 20 minutes of test running time (and we expect much more test cases to be written in the future). We&#8217;ll try to refactor that code so that this wait period is not necessary, but nevertheless these tests are written in a way that should allow parallel execution without any negative effects. In fact the parallelization would be welcome since it mimics the &quot;real&quot; situation in production.</p>

<p>Luckily with little Googling we found a thread on gallio-dev forum called &quot;<a href="http://groups.google.com/group/gallio-dev/browse_thread/thread/dcdad7c8e12be210/2ee05fdc939efa55?lnk=gst&amp;q=parallelizable#2ee05fdc939efa55">best way to parallelize a test suite</a>&quot; in which Jeff Brown (Gallio arhictect) discusses a new experimental addition to Gallio &#8211; the <strong>Parallelizable</strong> attribute. It can be applied both to test fixtures and test methods. From what I discerned, the Parallelizable attribute applied on test fixtures means that two or more fixtures can run in parallel, while marking test methods Parallelizable means that two or more test methods in the same fixture run in parallel (I simplified description a little here, for more details please read the mentioned thread).</p>

<p>We needed the second option (parallelization of methods), so I downloaded <a href="http://ccnet.gallio.org/Distributables/">the latest Gallio package</a>, marked all of our test methods with Parallelizable attribute&#8230;</p>

<div class="dean_ch" style="white-space: wrap;"><span class="br0">&#91;</span>Test<span class="br0">&#93;</span><br />
<span class="br0">&#91;</span>Metadata<span class="br0">&#40;</span><span class="st0">&quot;UserStory&quot;</span>, <span class="st0">&quot;SMSUi.AddSubs.Schedule&quot;</span><span class="br0">&#41;</span><span class="br0">&#93;</span><br />
<span class="br0">&#91;</span>Parallelizable<span class="br0">&#93;</span><br />
public <span class="kw4">void</span> AddScheduledSubs<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; &#8230;</div>

<p>&#8230;and run tests with Gallio.Echo runner. So far so good &#8211; the test do run in parallel, although occasionally the runner throws some exceptions, we&#8217;ll need to investigate this further (after all, this is an experimental feature, so I&#8217;m expecting it to break once in a while <img src='http://igorbrejc.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> .</p>

<p>You can set the rough number of concurrent threads that will process test code by setting <strong>DegreeOfParallelism</strong> value:</p>

<div>
  <div class="dean_ch" style="white-space: wrap;"><span class="br0">&#91;</span>FixtureSetUp<span class="br0">&#93;</span><br />
public <span class="kw4">void</span> FixtureSetup<span class="br0">&#40;</span><span class="br0">&#41;</span><br />
<span class="br0">&#123;</span><br />
&nbsp; &nbsp; Gallio.<span class="me1">Framework</span>.<span class="me1">Pattern</span>.<span class="me1">PatternTestGlobals</span>.<span class="me1">DegreeOfParallelism</span> = <span class="nu0">20</span>;<br />
<span class="br0">&#125;</span></div>
</div>

<p>NOTE: I&#8217;ve added this code to the fixture setup method because I didn&#8217;t know any better place to put it. Also, it would be better not to hard-code it like I did, use a configuration file instead.</p>

<h3>Conclusion</h3>

<p>Not all tests can be executed in parallel, of course. Once we integrate Selenium into acceptance testing we will have to be careful when selecting which tests should be parallelized and which should not &#8211; until we give the Selenium Grid a try, we will have to run Web UI tests on a single thread. I guess the best thing to do is keep non-parallalizable tests in fixtures separate from parallelized ones.</p>
]]></content:encoded>
			<wfw:commentRss>http://igorbrejc.net/development/continuous-integration/gallio-running-tests-in-parallel/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:thumbnail url="http://farm3.static.flickr.com/2368/2423144088_cb47aa7b45_m.jpg" />
		<media:content url="http://farm3.static.flickr.com/2368/2423144088_cb47aa7b45_m.jpg" medium="image">
			<media:title type="html">parallel</media:title>
		</media:content>
		<media:content url="http://igorbrejc.net/wp-content/plugins/photo-dropper/images/cc.png" medium="image">
			<media:title type="html">Creative Commons License</media:title>
		</media:content>
	</item>
		<item>
		<title>Gallio: Setting Test Outcome Any Way You Like</title>
		<link>http://igorbrejc.net/development/continuous-integration/gallio-setting-test-outcome-anyway-you-like</link>
		<comments>http://igorbrejc.net/development/continuous-integration/gallio-setting-test-outcome-anyway-you-like#comments</comments>
		<pubDate>Thu, 15 Jan 2009 10:05:48 +0000</pubDate>
		<dc:creator>breki</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[continuous integration]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[Gallio and MbUnit]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://igorbrejc.net/?p=258</guid>
		<description><![CDATA[photo credit: duimdog &#160; In one of my previous posts I discussed using Assert.Inconclusive() method to mark tests as &#34;not finished yet&#34; during the execution of the test (as opposed to declaring test outcomes using attributes such as [Pending]). It turns out there&#8217;s a better way to do this (which Jeff Brown kindly pointed me [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.flickr.com/photos/51367743@N00/35438353/" title="IMG_1927" target="_blank"><img src="http://farm1.static.flickr.com/29/35438353_806f939060_m.jpg" alt="IMG_1927" border="0" /></a><br /><small><a href="http://creativecommons.org/licenses/by-nc/2.0/" title="Attribution-NonCommercial License" target="_blank"><img src="http://igorbrejc.net/wp-content/plugins/photo-dropper/images/cc.png" alt="Creative Commons License" border="0" width="16" height="16" align="absmiddle" /></a> <a href="http://www.photodropper.com/photos/" target="_blank">photo</a> credit: <a href="http://www.flickr.com/photos/51367743@N00/35438353/" title="duimdog" target="_blank">duimdog</a></small></p>

<p>&#160;</p>

<p>In <a href="http://igorbrejc.net/?p=223">one of my previous posts</a> I discussed using Assert.Inconclusive() method to mark tests as &quot;not finished yet&quot; <strong>during</strong> the execution of the test (as opposed to declaring test outcomes using attributes such as [Pending]). </p>

<p>It turns out there&#8217;s a better way to do this (which <a href="http://blog.bits-in-motion.com/">Jeff Brown</a> kindly pointed me to): </p>

<div class="dean_ch" style="white-space: wrap;"> &nbsp; &nbsp;throw new SilentTestException<span class="br0">&#40;</span>TestOutcome.<span class="me1">Pending</span>, <span class="st0">&quot;To be implemented.&quot;</span><span class="br0">&#41;</span>;</div>

<p>SilentTestException allows you to mark the test with <a href="http://www.gallio.org/api/html/T_Gallio_Model_TestOutcome_Members.html">any outcome you like</a>. Which is exactly what I was looking for.</p>
]]></content:encoded>
			<wfw:commentRss>http://igorbrejc.net/development/continuous-integration/gallio-setting-test-outcome-anyway-you-like/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:thumbnail url="http://farm1.static.flickr.com/29/35438353_806f939060_m.jpg" />
		<media:content url="http://farm1.static.flickr.com/29/35438353_806f939060_m.jpg" medium="image">
			<media:title type="html">IMG_1927</media:title>
		</media:content>
		<media:content url="http://igorbrejc.net/wp-content/plugins/photo-dropper/images/cc.png" medium="image">
			<media:title type="html">Creative Commons License</media:title>
		</media:content>
	</item>
	</channel>
</rss>

