<?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>ORTHOcoders &#187; Unit Testing</title>
	<atom:link href="http://orthocoders.com/category/unit-testing/feed/" rel="self" type="application/rss+xml" />
	<link>http://orthocoders.com</link>
	<description>U can code it, we can help</description>
	<lastBuildDate>Fri, 13 Jan 2012 07:16:10 +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>The Bowling Game Kata &#8211; First attempt</title>
		<link>http://orthocoders.com/2011/09/05/the-bowling-game-kata-first-attempt/</link>
		<comments>http://orthocoders.com/2011/09/05/the-bowling-game-kata-first-attempt/#comments</comments>
		<pubDate>Tue, 06 Sep 2011 05:55:41 +0000</pubDate>
		<dc:creator>Amir Barylko</dc:creator>
				<category><![CDATA[BDD]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Kata]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[Training]]></category>
		<category><![CDATA[Unit Testing]]></category>

		<guid isPermaLink="false">http://orthocoders.com/?p=400</guid>
		<description><![CDATA[Katas are practice exercises to keep your skills sharp. The Bowling Kata lets you model the game and the rules.]]></description>
			<content:encoded><![CDATA[<p>Last week I did a presentation about the <a title="Uncle Bob's Bowling Game Kata" href="http://butunclebob.com/ArticleS.UncleBob.TheBowlingGameKata" target="_blank">Bowling Game kata</a> in C#.</p>
<p>I created a <a title="Bowling Game Src Code @ GitHub" href="https://github.com/amirci/bowling_game" target="_blank">repository</a> on GitHub with the code so I can share my first attempt.</p>
<p>You can follow the commit comments to get an idea of the train of thought.</p>
<p>Or if u prefer, just keep reading <img src='http://orthocoders.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h2>The Methodology</h2>
<p>I used TDD and somehow BDD all the way. Started with an acceptance test and jumped in and out from the unit tests until the feature passed.</p>
<p>Why is a good idea to start with an acceptance test?</p>
<p>When you know where you want to go, what you want to achieve, is easier to keep the focus.</p>
<p>Having a way of identifying if the current feature is finished is a lot of power in your hands, so do the minimum necessary to make it work and then &#8211; once the test is passing &#8211; do refactoring as you see fit.</p>
<p>In the solution you will find three projects:</p>
<ol>
<li>BowlingKata: Classes that implement the Kata</li>
<li>BowlingKata.Unit.Tests: Unit tests</li>
<li>BowlingKata.Acceptance.Test: Features that I&#8217;m looking for in a bowling game</li>
</ol>
<h2>Design Decisions (fast forward TDD)</h2>
<p>As soon as I started to write a unit test for the <em>BowlingGame</em> class I wonder how am I going to design the solution.</p>
<p>My first test was for the method <em>Roll(pins)</em>. And right there I had to assign responsibilities.</p>
<p>What should this method do? Do the &#8220;registration&#8221; only? Do the calculation as well? Is there any other class involved?</p>
<p>I decided on keep things simple and separate two clear responsibilities:</p>
<ol>
<li>Keeping the number of pins knocked down on each ball (or frames later)</li>
<li>Calculating the score based on the information on each frame</li>
</ol>
<div>So I created two interfaces with that purpose:</div>
<div>
<ul>
<li><em>IFrameKeeper</em>: In charge of registering the pins down in each frame</li>
<li><em>IScoreCalculator</em>: in charge of calculating the score over a sequence of frames (10 frames + 1 optional extra)</li>
</ul>
<div>You can follow all the tests to see how the interfaces grew in complexity to fullfil the intended responsibility.</div>
<div>
<h2>What&#8217;s next?</h2>
<p>After the first approach I thought that would be nice to refactor again and explore other solutions:</p>
<ul>
<li>Change the frame class <em>IBowlingFrame</em> to be able to calculate the score, maybe having regular frames, spare, and strike.</li>
<li>Find a way of registering the pins and also add some kind of bonus to avoid the iteration over the frames to get the score</li>
</ul>
<div>Which option did you implement? Please share!</div>
<div>Feedback is more than welcome.</div>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://orthocoders.com/2011/09/05/the-bowling-game-kata-first-attempt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Testing with random values: is it really dangerous?</title>
		<link>http://orthocoders.com/2011/03/06/testing-with-random-values-is-it-really-dangerous/</link>
		<comments>http://orthocoders.com/2011/03/06/testing-with-random-values-is-it-really-dangerous/#comments</comments>
		<pubDate>Mon, 07 Mar 2011 04:37:34 +0000</pubDate>
		<dc:creator>Amir Barylko</dc:creator>
				<category><![CDATA[BDD]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Presentations]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[Unit Testing]]></category>

		<guid isPermaLink="false">http://orthocoders.com/?p=254</guid>
		<description><![CDATA[Using random values can be a great tool when writing any kind of tests, however the word "random" sometimes scare developers and gives the idea that if we use unknown values how can we be sure the test is actually working? The key is to discover the tests scenarios, and the valid domain for each scenario...]]></description>
			<content:encoded><![CDATA[<p>Last Saturday I presented a session about automation at the Winnipeg Code Camp.</p>
<p>I&#8217;ve been doing presentations a the WPG CC for the past three years, and is always a blast! Great sessions, lots of networking and great food is an awesome combination!</p>
<p>After my session, some of the attendes approached me and started to talk about CI, their gotchas about testing and woes <img src='http://orthocoders.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p>One of them mentioned that he wasn&#8217;t sure about the way they were using &#8220;hardcoded&#8221; values with the tests. He felt that probably should be a better way of defining valid inputs that could avoid the &#8220;smell&#8221;.</p>
<p>My suggestions was to consider using auto generated values. Random values are a great tool to avoid hardcoding inputs. Using &#8220;factories&#8221; to create valid test values helps us to make sure we have better coverage of the domain of valid inputs for our tests.</p>
<h2>How do I know what input is valid?</h2>
<p>You may wonder &#8220;But, if the values are random, the test may pass once and then fail at runtime, that&#8217;s really, really, dangerous!!!&#8221;.</p>
<p>The answer is <strong>No</strong>, not at all. The key is to identify the domain that makes your test pass and use the random generation tools to get values that are part of that domain. How to do that? Keep reading &#8230;</p>
<p>When you write a unit test you may have more than one scenario. For each scenario you need to find a set of inputs that make it pass.</p>
<p>For example, let&#8217;s use a method that verifies if a string is a <em>palindrome</em>. Definition of <em>palindrome</em> in wikipedia:</p>
<blockquote><p>A <strong>palindrome</strong> is a word, phrase, <a title="Palindromic number" href="http://en.wikipedia.org/wiki/Palindromic_number">number</a> or other sequence of units that can be read the same way in either direction</p></blockquote>
<p>Our method may look something like this in C#:</p>
<pre class="brush: csharp; title: ; notranslate">
bool IsPalindrome(string word)
</pre>
<p>So now, what should we do? Write one test that takes random strings as input, run it once and if we are lucky and passes then we are done? Woah, slow down your horses&#8230;.. take a deep breath&#8230; maybe two&#8230;.</p>
<h2>Preconditions, postconditions and domains</h2>
<p>The <em>precondition</em> of the method is the set of values that are valid in order to call the method. Valid means that we don&#8217;t get an exception when we use it, no matter what the result of the method is.</p>
<p>So, what are the values that are valid to use for <em>IsPalindrome</em>? It seems to me that any string should work, except <em>null</em>, therefore:</p>
<ul>
<li>Precondition: Any <strong>not</strong> <em>null</em> <em>string</em> instance.</li>
</ul>
<p>Great! Now let&#8217;s think about the <em>postcondition</em> and discover our scenarios. The <em>postcondition</em> defines what are the expected results and under what conditions are calculated.</p>
<p>Following our definition of what the method does, we can have two possible outputs:</p>
<ul>
<li><em>True: </em>if the input is <em>palindrome </em></li>
<li><em>False</em>: if the input is <strong>not</strong> <em>palindrome</em></li>
</ul>
<p>Thus, we have two scenarios:</p>
<ul>
<li>When the word is palindrome it should return true</li>
<li>When the word is not palindrome it should return false</li>
</ul>
<h2>Writing the test</h2>
<p>We need to test two scenarios and the best way of doing that is to write one test per scenario.</p>
<p>The first test should check the first part of the <em>postcondition</em>, I want to get <em>true </em>as result, and to do that the domain I need to use would be all the words that actually are <em>palindrome</em>. Let&#8217;s write the scenario:</p>
<blockquote><p><strong>Given</strong> I have a <em>palindrome</em> phrase</p>
<p><strong>When</strong> I check <em>IsPalindrome</em></p>
<p><strong>Then</strong> I should get <em>true</em></p></blockquote>
<p>I like to use the <a title="Using Given-When-Then (GWT) syntax" href="https://github.com/amirci/mt_testing/wiki/Given-When-Then">Given-When-Then</a> syntax, it&#8217;s very descriptive. I&#8217;m using the <a title="Maventhought Testing Framework" href="https://github.com/amirci/mt_testing">MT Testing</a> library that enforces GWT. Here is the scenario using C# and just one example:</p>
<pre class="brush: csharp; title: ; notranslate">
protected override void GivenThat()
{
    this._phrase = &quot;Madam Im adam&quot;;
}

protected override void WhenIRun()
{
   this.Actual = PalindromeChecker.IsPalindrome(this._phrase);
}

[It]
public void Should_validate_the_phrase_is_palindrome()
{
    this.Actual.Should().Be.True();
}
</pre>
<p>The test looks good, a bit of TDD and all green. Don&#8217;t worry about the implementation, you can <a title="MT Testing library with the example" href="https://github.com/amirci/mt_testing">download</a> all the source and check it out at the later <img src='http://orthocoders.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> .</p>
<h2>Using Factories</h2>
<p>I&#8217;d like to make sure that for any <em>palindrome</em> phrase (that&#8217;s the domain we got from the pre and post condition) the test passes, no just for one example.</p>
<p>However, though generating all the <em>palindrome </em>words is a bit ambitious, we could settle for generating a collection of phrases that are <em>palindrome</em> and use that as input.</p>
<p><a title="MbUnit V3" href="http://gallio.org/">MbUnit</a> provides an attribute named &#8220;Factory&#8221; that allows a <em>static method</em> to define a collection of values to be passed to the test, let&#8217;s look at the code:</p>
<pre class="brush: csharp; title: ; notranslate">
        private readonly string _phrase;

        [Factory(&quot;PalindromeFactory&quot;)]
        public When_palindrome_checker_checks_a_palindrome_phrase(string phrase)
        {
            _phrase = phrase;
        }

        protected override void WhenIRun()
        {
            this.Actual = PalindromeChecker.IsPalindrome(this._phrase);
        }

        [It]
        public void Should_check_the_word_as_palindrome()
        {
            this.Actual.Should().Be.True();
        }

        protected static IEnumerable&lt;string&gt; PalindromeFactory()
        {
            yield return &quot;Madam I'm adam&quot;;
            yield return &quot;Draw pupil's lip upward&quot;;
            yield return ....
        }
</pre>
<p>Using the attribute, we indicate the runner that the test should be run for every value in the collection.</p>
<p>We run the test, and we can see in the result window something like:</p>
<p>### Step When_palindrome_checker_checks_a_palindrome_phrase(&quot;Madam I\&#8217;m adam&quot;): passed ###<br />
### Step When_palindrome_checker_checks_a_palindrome_phrase(&quot;Draw pupil\&#8217;s lip upward&quot;): passed ###<br />
### Step When_palindrome_checker_checks_a_palindrome_phrase(&quot;Gateman sees name, garageman sees name tag&quot;): passed ###<br />
### Step When_palindrome_checker_checks_a_palindrome_phrase(&quot;Go hang a salami; I\&#8217;m a lasagna hog&quot;): passed ###<br />
### Step When_palindrome_checker_checks_a_palindrome_phrase(&quot;I roamed under it as a tired, nude Maori&quot;): passed ###<br />
### Step When_palindrome_checker_checks_a_palindrome_phrase(&quot;Live not on evil&quot;): passed ###</p>
<h2>Using random strings</h2>
<p>One case covered, one to go.</p>
<p>The second test should verify the second part of the <em>postcondition</em>. I want to get <em>false</em> as result, so the domain I need to use is all the words that are <em>not palindrome</em>. Let&#8217;s write the scenario:</p>
<blockquote><p><strong>Given</strong> I don&#8217;t have palindrome phrase</p>
<p><strong>When</strong> I check IsPalindrome</p>
<p><strong>Then</strong> I should get false</p></blockquote>
<p>And the code:</p>
<pre class="brush: csharp; title: ; notranslate">
        private string _phrase;

        protected override void GivenThat()
        {
            this._phrase = &quot;This is not palindrome&quot;;
        }

        protected override void WhenIRun()
        {
            this.Actual = PalindromeChecker.IsPalindrome(this._phrase);
        }

        [It]
        public void Should_not_validate_the_phrase_as_palindrome()
        {
            this.Actual.Should().Be.False();
        }
</pre>
<p>The code works fine. However we have a similar situation as before, I&#8217;d like to have more values that belong to the domain that makes the method fail, that means any phrase that is <em>not palindrome</em>.</p>
<p>Factories are a good idea when we have a set of values that we want to use. In this case I don&#8217;t want to hardcode <em>non palindrome</em> phrases. I would prefer to have a way of creating those phrases without needing to enumerate all the examples.</p>
<p>Luckily MbUnit has another attribute that we can use to generate random strings. It&#8217;s called <em>RandomStrings</em> and it takes a regular expression to describe the string. Adding the attribute the code looks like this:</p>
<pre class="brush: csharp; title: ; notranslate">
        private readonly string _phrase;

        public When_palindrome_checker_checks_a_non_palindrome_phrase(
            [RandomStrings(Count=10, Pattern=@&quot;Weird [A-Z]{5,8} [0-9]{2}&quot;)]string phrase)
        {
            _phrase = phrase;
        }

        protected override void WhenIRun()
        {
            this.Actual = PalindromeChecker.IsPalindrome(this._phrase);
        }

        [It]
        public void Should_not_validate_the_phrase_as_palindrome()
        {
            this.Actual.Should().Be.False();
        }
</pre>
<p>I&#8217;m using a regular expression that <em>uses </em>numbers at the end to make sure the phrase is not <em>palindrome</em>.</p>
<p>We run the tests, and here is the output:</p>
<p>### Step When_palindrome_checker_checks_a_non_palindrome_phrase(&quot;Weird VGSKTTZ 64&quot;): passed ###<br />
### Step When_palindrome_checker_checks_a_non_palindrome_phrase(&quot;Weird VLMEWIJ 59&quot;): passed ###<br />
### Step When_palindrome_checker_checks_a_non_palindrome_phrase(&quot;Weird NDICJK 08&quot;): passed ###<br />
### Step When_palindrome_checker_checks_a_non_palindrome_phrase(&quot;Weird FEMBMSKK 88&quot;): passed ###<br />
### Step When_palindrome_checker_checks_a_non_palindrome_phrase(&quot;Weird IHOIOWN 38&quot;): passed ###<br />
### Step When_palindrome_checker_checks_a_non_palindrome_phrase(&quot;Weird ITIRCHAA 63&quot;): passed ###</p>
<h2>The moral of the story</h2>
<p>Random values are a powerful tool, not dangerous per se. They are part of our toolbox as developers. Can we use it wrong? Sure, but that&#8217;s a completely different story &#8230;.</p>
<p>If you want to get the full code, download it from the examples in <a title="MavenThought Testing Framework" href="https://github.com/amirci/mt_testing">MT Testing</a>. Check the <em>Palindrome</em> folder.</p>
<p>Do you have any other stories or comments about random values that you would like to share, please leave a comment, feedback is more than welcome.</p>
<p>Want to see an example with major complexity? Something that fits better your case? Tell me about it and I&#8217;ll add it to the MT Testing framework as an example of usage (and I&#8217;ll give you credit for it too!).</p>
]]></content:encoded>
			<wfw:commentRss>http://orthocoders.com/2011/03/06/testing-with-random-values-is-it-really-dangerous/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Real world BDD introduction</title>
		<link>http://orthocoders.com/2010/05/26/real-world-bdd-introduction/</link>
		<comments>http://orthocoders.com/2010/05/26/real-world-bdd-introduction/#comments</comments>
		<pubDate>Thu, 27 May 2010 02:58:40 +0000</pubDate>
		<dc:creator>Amir Barylko</dc:creator>
				<category><![CDATA[BDD]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Presentations]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[Training]]></category>
		<category><![CDATA[Unit Testing]]></category>
		<category><![CDATA[PrairieDevCon]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://orthocoders.com/?p=162</guid>
		<description><![CDATA[Getting ready for PrairieDevCon Next week I’ll be presenting at the PrairieDevCon in Regina and one of my presentations is about Behavior Driven Development, how to apply it using .NET tools like SpecFlow, Nunit, Watin, Cassini, MbUnit, etc. Because is a Dojo/Code with me presentation I’m planning to do a BDD exercise with all the [...]]]></description>
			<content:encoded><![CDATA[<h3>Getting ready for PrairieDevCon</h3>
<p>Next week I’ll be presenting at the <a href="http://www.prairiedevcon.com" target="_blank">PrairieDevCon</a> in Regina and one of my presentations is about Behavior Driven Development, how to apply it using .NET tools like SpecFlow, Nunit, Watin, Cassini, MbUnit, etc.</p>
<p>Because is a Dojo/Code with me presentation I’m planning to do a BDD exercise with all the attendees to show them how to describe a new feature using BDD and implement it together.</p>
<p>We will start with a project that has one feature implemented, and will code together the second feature using full BDD and TDD.</p>
<p>So, what should I use to illustrate BDD? No other than my old friend the MediaLibrary example that I used quite a few times, but now including a full BDD implementation.</p>
<h3>MediaLibrary</h3>
<p>The MediaLibrary project is a web application that  allows the user to register and catalog his collection of movies, books, games, etc.</p>
<p>I’m using GitHub to publish the code we are going to use in the Dojo. Right now the latest version represents the code that I’m going to start with.</p>
<p>If you would like to check out the code I’m going to use please go to the <a href="http://orthocoders.com/prairiedevcon/" target="_blank">PrairieDevCon page</a> on my blog and get the code from <a href="http://github.com/amirci/Media-Library-Demo-PrairieDevCon-2010" target="_blank">GitHub</a>, read the README file to verify you have the requirements installed and the application is working.</p>
<p>Do you have everything installed? Did you read the README file? Cool, open the solution and let’s move on!</p>
<h3>Using BDD</h3>
<p>Behavior Driven Development is a term used to describe (in our case) development that starts by writing the feature (or user story) that we want to implement. Once we have the feature, we will use a “story runner” that will run the feature we just wrote and show if the story is actually implemented as we wanted or not yet. If it is, good, everything should be “green”. If not, we get a “red”, and we have to add code and implement more functionality to make it pass.</p>
<p>To write the user story we are going to use a particular syntax from the Gherkin language. The Gherkin language has very few rules, please read the introduction for Cucumber from <a title="http://wiki.github.com/aslakhellesoy/cucumber/gherkin" href="http://wiki.github.com/aslakhellesoy/cucumber">Aslak Hellesoy</a>.</p>
<p>Let’s see the feature that it’s implemented in the code, <em>Browse Movies:</em></p>
<pre class="code"><span style="color: blue;">Feature: </span>Browse Movies
    As a User
    I want to Browse Movies
    So I can see the contents of the library

    <span style="color: blue;">Scenario: </span>Browse available movies
        <span style="color: blue;">Given </span><span style="color: green;">I have the following movies:
          </span>| title           |
          | Blazing Saddles |
          | Space Balls     |
        <span style="color: blue;">When </span><span style="color: green;">I go to </span><span style="color: red;">Movies
        </span><span style="color: blue;">Then </span><span style="color: green;">I should see in the listing:
          </span>| title             |
          | Blazing Saddles   |
          | Space Balls       |</pre>
<p>What is most important here is to look at the scenario. The scenario is describing that if you have movies A, B and C in the library, when you browse you should see the same movies on the <em>Movies</em> page.</p>
<p>Now if we want to check the feature manually, what would we do? Something like this:</p>
<ol>
<li>Add the movies to the storage</li>
<li>Start the web application</li>
<li>Launch the browser</li>
<li>Go to the movies page</li>
<li>Check that all the movies in the storage are listed in the browser</li>
</ol>
<p>The thing is that I don’t want to validate each feature (with many scenarios) manually, I’d like the scenario/feature runner to do that for me, add the movies, launch the browser and check, everything automated following the steps I wrote in my scenario.</p>
<p>Probable we could manage to write code that will do that for us, now, the question is how the scenario runner translates this feature into actual code? If we were using rails we could use <em>Cucumber, </em>but luckily for the .NET world we can use <a href="http://www.specflow.org">SpecFlow</a> (<em><a href="http://ironruby.net/download">IronRuby</a></em> too, but that’s another post).</p>
<h3>Given That I have the following movies</h3>
<p>Specflow is a tool that understands <a href="http://wiki.github.com/aslakhellesoy/cucumber/gherkin">Gherkin</a> and generates an <a href="http://nunit.org/">NUnit</a> test for every feature that we use. Being an NUnit test, simplifies how we going to run the specification. Just run the NUnit test with your favorite test runner: <a href="http://www.jetbrains.com/resharper/">ReSharper</a>, NUnit (console or GUI), <a href="http://www.gallio.org">MbUnit</a>, etc.</p>
<p>Each scenario is composed by a series of steps, each step is identified by a Gherkin keyword, in our feature we found <em>Given, When</em> and <em>Then.</em></p>
<p>The NUnit test has code for each scenario and will invoke the steps indicated in the scenario.</p>
<p>In order to do so, Specflow uses the text that we write in the step, to match the code.</p>
<p>Let’s look at our first step “Given I have the following movies:”. In order to implement the step, in the code, you will find a method that looks like:</p>
<pre class="code">[<span style="color: #2b91af;">Given</span>(<span style="color: #a31515;">@"I have the following movies:"</span>)]
<span style="color: blue;">public void </span>AddMovies(<span style="color: #2b91af;">Table </span>movies)
{
    movies.Rows.ForEach(row =&gt; AddMovieToStorage(row[<span style="color: #a31515;">"title"</span>]));
}</pre>
<p>The <em>Given</em> attribute is used to match the text we wrote in the scenario, to indicate the the method <em>AddMovies</em> should be called when the step is invoked.</p>
<p>The step in the scenario indicates that the method receives a series of rows should be passed as parameter (first row is the title, every column separated by “|”), that is why it receives a <em>Table</em>.</p>
<p>In the implementation for each movie in the table, the title will be added to the storage. Check the method <em>AddMoviesToStorage</em> for more details.</p>
<p>Now that we setup our storage we are ready to move on and launch the browser.</p>
<h3>When I go to Movies</h3>
<p>The next step to implement implies opening the browser and going to the <em>Movies </em>page to see the listing<em>.</em></p>
<p>Now, to do so we need two things, first the web application running and then to launch a browser to go the actual page.</p>
<p>To run the application I’m going to use <a href="http://www.asp.net/downloads/archived-v11/cassini">Cassini</a> web server. The setup of the features will start the web server and stop it when it’s not needed any more. We can see the implementation in the <em>Browser </em>class under Utililty.</p>
<pre class="code"><span style="color: blue;">static </span>Browser()
{
    WebServer = <span style="color: blue;">new </span><span style="color: #2b91af;">Server</span>(Port, <span style="color: #a31515;">"/"</span>, GetPhysicalPath());
}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>With the server running, we now need to launch the browser and automate the checking for all the movies.</p>
<p>For that we are going to use<em> </em>Watin. <a href="http://watin.sourceforge.net/">Watin</a> (Web automation test in .NET) is a library that helps us to manipulate the browser (based on <a href="http://watir.com/">Watir</a>) and also give us all the HTML for the page we are visiting.</p>
<p>We can see the use of the <em>IE </em>instance in the <em>Browser</em> class:</p>
<pre class="code"><span style="color: blue;">public static void </span>InitializeBrowser()
{
    WebServer.Start();

    Instance = <span style="color: blue;">new </span><span style="color: #2b91af;">IE</span>(ApplicationURL);
}

<span style="color: blue;">public static void </span>ShutdownBrowser()
{
    Instance.Close();

    WebServer.Stop();
}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>Now that we have our server running, and our <em>IE</em> instance, we only need to go to the right path. In this case we want to go to “/Movies”. For that let’s look at the <em>NavigationSteps class:</em></p>
<pre class="code">[<span style="color: #2b91af;">When</span>(<span style="color: #a31515;">@"I go to (.*)"</span>)]
<span style="color: blue;">public void </span>WhenIGoToPage(<span style="color: blue;">string </span>pageName)
{
    <span style="color: #2b91af;">Browser</span>.GoTo(PathFor(pageName));
}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>The step uses the browser to navigate to the right page. The page is passed as a parameter that we can see in the attribute as a regular expression.</p>
<p>So far, so good. Now, our last step is to check for the movies in the page to make sure that all of them are in the list.</p>
<h3>Then I should see in the listing</h3>
<p>To implement the last step in our scenario we are going to use the following implementation:</p>
<pre class="code">[<span style="color: #2b91af;">Then</span>(<span style="color: #a31515;">@"I should see in the listing:"</span>)]
<span style="color: blue;">public void </span>AssertListingContains(<span style="color: #2b91af;">Table </span>movies)
{
    <span style="color: blue;">var </span>expected = movies.Rows.Select(row =&gt; row[<span style="color: #a31515;">"title"</span>]);

    <span style="color: blue;">var </span>listing = <span style="color: blue;">this</span>.Page.Listing;

    listing.Should().Have.SameSequenceAs(expected);
}</pre>
<p>Again we are using a step that takes a table as parameter, so we iterate thru the table and get the titles of all the movies that should be in the page.</p>
<p>The code has no mysteries except the <em>Page</em> property.</p>
<pre class="code"><span style="color: blue;">public </span>ListingSteps()
{
    <span style="color: blue;">this</span>.Page = <span style="color: blue;">new </span><span style="color: #2b91af;">BrowseMoviesPage</span>();
}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>The <em>Page</em> property is initialized in the constructor and the goal of the <em>BrowseMoviesPage</em> is to abstract the internals of how the movies are listed in the page. For example, right now the view that implements the listing of movies uses a table for each movie, however it could use a <em>DIV</em> or some other tag. Here is the implementation:</p>
<pre class="code"><span style="color: blue;">public </span><span style="color: #2b91af;">IEnumerable</span>&lt;<span style="color: blue;">string</span>&gt; Listing
{
    <span style="color: blue;">get
    </span>{
        <span style="color: blue;">var </span>elements = <span style="color: #2b91af;">Browser</span>.Instance.TableCells.Where(cell =&gt; cell.ClassName == <span style="color: #a31515;">"title"</span>);

        <span style="color: blue;">return </span>elements.Select(e =&gt; e.InnerHtml.Trim());
    }
}</pre>
<p><a href="http://11011.net/software/vspaste"></a></p>
<p>As we can see, the code is getting all the table cells where the <em>CSS</em> class is <em>title</em> and then getting the inner html and trimming it.</p>
<p>If we would have to use this code every time we want to check the listing we would have code duplication, plus if the implementation of the view changes, we would have to modify each piece of code that refers to this page. Using the <em>PageObject</em> pattern we avoid code duplication and it’s easy to change the implementation.</p>
<p>And voila! We got all our steps implemented.</p>
<h3>What’s next?</h3>
<p>If you join me next week on the Prairie Dev Con, we will implement the next feature together “<em>Add Movies”.</em></p>
<p>What’s so cool about BDD? Please go ahead and run “rake test:features” on the command line, and you’ll see that the steps for the second feature are still pending, that means that they are not implemented yet.</p>
<p>Writing the feature first we manage to describe what we want, and implementing step by step we make sure that we are working towards make the feature pass. BDD on the outside and TDD on the inside.</p>
<p>Hope to see you all next week in the conference!</p>
]]></content:encoded>
			<wfw:commentRss>http://orthocoders.com/2010/05/26/real-world-bdd-introduction/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Prairie Development Conference</title>
		<link>http://orthocoders.com/2010/05/03/prairie-development-conference/</link>
		<comments>http://orthocoders.com/2010/05/03/prairie-development-conference/#comments</comments>
		<pubDate>Tue, 04 May 2010 03:14:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[BDD]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[Patterns]]></category>
		<category><![CDATA[Presentations]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[Unit Testing]]></category>
		<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Mocking]]></category>
		<category><![CDATA[SOLID]]></category>

		<guid isPermaLink="false">http://orthocoders.com/2010/05/03/prairie-development-conference/</guid>
		<description><![CDATA[On Jun 2nd and 3rd I’ll be speaking at the PrairieDevCon 2010 in Regina!!! You can read about it at http://www.prairiedevcon.com/. It would be two complete days of sessions with four tracks and many cool speakers!!!! I will do two presentations: Real World Behaviour Driven Development Behaviour Driven Development drives you process towards keeping the [...]]]></description>
			<content:encoded><![CDATA[<p>On Jun 2nd and 3rd I’ll be speaking at the <strong>PrairieDevCon</strong> 2010 in Regina!!!</p>
<p><a href="http://orthocoders.com/wp-content/uploads/2010/05/Prairie_Dev_Con_Presenter.gif"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="Prairie_Dev_Con_Presenter" src="http://orthocoders.com/wp-content/uploads/2010/05/Prairie_Dev_Con_Presenter_thumb.gif" border="0" alt="Prairie_Dev_Con_Presenter" width="225" height="123" /></a></p>
<p>You can read about it at <a href="http://www.prairiedevcon.com/">http://www.prairiedevcon.com/</a>. It would be two complete days of sessions with four tracks and many cool speakers!!!!</p>
<p>I will do two presentations:</p>
<p><strong> </strong></p>
<h5>Real World Behaviour Driven Development</h5>
<p>Behaviour Driven Development drives you process towards keeping the focus on the stakeholder’s goals while discovering new features to achieve those goals.<br />
But&#8230; what does it mean in a .NET project to use BDD? What do I have to change? What tools are available? Can I use it for project with actual deadlines? How the quality will be improved?<br />
We are going to see a real world example from start to finish using BDD and TDD while answering all those questions. After the session you will have the foundation to apply BDD with confidence on any .NET project.<br />
<strong>Track:</strong> Developer Foundation<br />
<strong>Style:</strong> Dojo (Bring your laptop and code with me!)</p>
<h5>Test Driven Development Patterns for .NET Developers</h5>
<p>Test Driven Development is a methodology that will help us to discover our model while improving the quality of our software.<br />
We are going to see different patterns to help us deal with day to day problems like constructor initialization, exception testing, combinatorial tests, database testing, and many others.<br />
<strong>Track:</strong> Developer Foundation<br />
<strong>Style:</strong> Lecture</p>
<p>Hope to see you there!!!</p>
]]></content:encoded>
			<wfw:commentRss>http://orthocoders.com/2010/05/03/prairie-development-conference/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Winnipeg Code Camp 2010</title>
		<link>http://orthocoders.com/2010/02/26/winnipeg-code-camp-2010/</link>
		<comments>http://orthocoders.com/2010/02/26/winnipeg-code-camp-2010/#comments</comments>
		<pubDate>Sat, 27 Feb 2010 05:13:47 +0000</pubDate>
		<dc:creator>Amir Barylko</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[Unit Testing]]></category>

		<guid isPermaLink="false">http://orthocoders.com/2010/02/26/winnipeg-code-camp-2010/</guid>
		<description><![CDATA[Winnipeg Code Camp 2010! I'll present two presentations, BDD and TeamCity, don't miss it....]]></description>
			<content:encoded><![CDATA[<p>Tomorrow I’ll be presenting at the <a href="http://winnipegcodecamp.com" target="_blank">Winnipeg Code Camp 2010</a>!</p>
<p>I’m super excited! This year I have two presentations:</p>
<ol>
<li>Real World BDD for .NET developers</li>
<li> Intro to TeamCity</li>
</ol>
<p>I just finished the last changes to the presentations, enjoy!</p>
<p><a href="http://orthocoders.com/wp-content/uploads/2010/02/2010-02-27-Code-Camp.zip">2010-02-27 Code Camp</a></p>
<p>See u tomorrow!</p>
]]></content:encoded>
			<wfw:commentRss>http://orthocoders.com/2010/02/26/winnipeg-code-camp-2010/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Code and presentation for .NET UG Automocking</title>
		<link>http://orthocoders.com/2009/11/19/code-and-presentation-for-net-ug-automocking/</link>
		<comments>http://orthocoders.com/2009/11/19/code-and-presentation-for-net-ug-automocking/#comments</comments>
		<pubDate>Thu, 19 Nov 2009 06:27:14 +0000</pubDate>
		<dc:creator>Amir Barylko</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[Unit Testing]]></category>
		<category><![CDATA[Automocking]]></category>

		<guid isPermaLink="false">http://orthocoders.com/?p=75</guid>
		<description><![CDATA[Here is the source code and presentation I&#8217;m going to use tomorrow. Presentation Automocking PPT Source Code AutoMocking Src Enjoy!]]></description>
			<content:encoded><![CDATA[<p>Here is the source code and presentation I&#8217;m going to use tomorrow.</p>
<p>Presentation <a href="http://orthocoders.com/wp-content/uploads/2009/11/Automocking.zip">Automocking PPT</a></p>
<p>Source Code <a href="http://orthocoders.com/wp-content/uploads/2009/11/AutoMocking.zip">AutoMocking Src</a></p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://orthocoders.com/2009/11/19/code-and-presentation-for-net-ug-automocking/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automocking with .NET</title>
		<link>http://orthocoders.com/2009/11/04/automocking-with-net/</link>
		<comments>http://orthocoders.com/2009/11/04/automocking-with-net/#comments</comments>
		<pubDate>Wed, 04 Nov 2009 20:36:27 +0000</pubDate>
		<dc:creator>Amir Barylko</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[Unit Testing]]></category>
		<category><![CDATA[Automocking]]></category>

		<guid isPermaLink="false">http://orthocoders.com/?p=58</guid>
		<description><![CDATA[Just confirmed! On Nov 19th I&#8217;ll be the host of the .NET user group meeting. This time we will talk about using StructureMap&#160; to generate our dependencies for our System Under Test (SUT). We will go over writing base specification for testing and how to generate dependencies and use them to stub or setup expectations. [...]]]></description>
			<content:encoded><![CDATA[<p>Just confirmed! On Nov 19th I&#8217;ll be the host of the .NET user group meeting.</p>
<p>This time we will talk about using StructureMap&nbsp; to generate our dependencies for our System Under Test (SUT). </p>
<p>We will go over writing base specification for testing and how to generate dependencies and use them to stub or setup expectations.</p>
<p>See u soon!</p>
<p></p>
]]></content:encoded>
			<wfw:commentRss>http://orthocoders.com/2009/11/04/automocking-with-net/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Mock The Mock AAA</title>
		<link>http://orthocoders.com/2009/06/08/mock-the-mock-aaa/</link>
		<comments>http://orthocoders.com/2009/06/08/mock-the-mock-aaa/#comments</comments>
		<pubDate>Tue, 09 Jun 2009 00:18:50 +0000</pubDate>
		<dc:creator>Amir Barylko</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[Unit Testing]]></category>

		<guid isPermaLink="false">http://orthocoders.com/?p=27</guid>
		<description><![CDATA[I updated the code I used for the mocking presentation at the code camp to use AAA syntax focusing on keeping the test simple and testing just one functionality per test. AAA syntax is part of the additions to Rhino Mocks 3.5. Here is a link with the explanation. Here is the complete source code [...]]]></description>
			<content:encoded><![CDATA[<p>I updated the code I used for the mocking presentation at the code camp to use AAA syntax focusing on keeping the test simple and testing just one functionality per test.<br />
AAA syntax is part of the additions to Rhino Mocks 3.5. Here is a <a href="http://ayende.com/Wiki/Rhino+Mocks+3.5.ashx#Arrange,Act,Assert" target="_blank">link</a> with the explanation.</p>
<p>Here is the complete source code with all the tests. <a href="http://orthocoders.com/wp-content/uploads/2009/05/codecamp_mockthemock.zip">Mock The Mock Source Code with AAA Syntax</a></p>
<p>Enjoy.</p>
]]></content:encoded>
			<wfw:commentRss>http://orthocoders.com/2009/06/08/mock-the-mock-aaa/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Winnipeg Code Camp 2009</title>
		<link>http://orthocoders.com/2009/03/15/winnipeg-code-camp-2009/</link>
		<comments>http://orthocoders.com/2009/03/15/winnipeg-code-camp-2009/#comments</comments>
		<pubDate>Sun, 15 Mar 2009 14:54:58 +0000</pubDate>
		<dc:creator>Amir Barylko</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Presentations]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[Unit Testing]]></category>
		<category><![CDATA[Mocking]]></category>

		<guid isPermaLink="false">http://orthocoders.com/?p=24</guid>
		<description><![CDATA[Wow! What a day! We started around 8 AM with breakfast and at 9 started the presentations. I did mine around 10:30, I think it was pretty good (no one faint, or run from the room screaming). The audience was great, made great questions and laughed (utter kindness) at my bad jokes. I want to [...]]]></description>
			<content:encoded><![CDATA[<p>Wow! What a day!</p>
<p>We started around 8 AM with breakfast and at 9 started the presentations.</p>
<p>I did mine around 10:30, I think it was pretty good (no one faint, or run from the room screaming).</p>
<p>The audience was great, made great questions and laughed (utter kindness) at my bad jokes.</p>
<p>I want to thank everyone that was there, and D&#8217;arcy for inviting me.</p>
<p>Here is the presentation <a href="http://orthocoders.com/wp-content/uploads/2009/03/talk-the-talk-and-mock-the-mock.zip">PDF presentation</a>, the source code <a href="http://orthocoders.com/wp-content/uploads/2009/03/mocktutorial_start.zip">Demo Code (start)</a> and the source code complete with all the tests <a href="http://orthocoders.com/wp-content/uploads/2009/03/mocktutorial_witheverything.zip">Demo Code with all the tests</a>.</p>
<p>The video is still to come <img src='http://orthocoders.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> !</p>
<p>Comments are welcome!</p>
]]></content:encoded>
			<wfw:commentRss>http://orthocoders.com/2009/03/15/winnipeg-code-camp-2009/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mock The Mock @ Winnipeg Code Camp</title>
		<link>http://orthocoders.com/2009/03/14/presentation-at-winnipeg-code-camp/</link>
		<comments>http://orthocoders.com/2009/03/14/presentation-at-winnipeg-code-camp/#comments</comments>
		<pubDate>Sat, 14 Mar 2009 06:21:19 +0000</pubDate>
		<dc:creator>Amir Barylko</dc:creator>
				<category><![CDATA[Presentations]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[Unit Testing]]></category>
		<category><![CDATA[Mocking]]></category>

		<guid isPermaLink="false">http://orthocoders.com/?p=22</guid>
		<description><![CDATA[I&#8217;m getting ready for the presentation tomorrow at the Winnipeg Code Camp! I&#8217;m going to talk about mocking using Rhino Mocks. Here is the presentation: PDF presentation download. I&#8217;ll try to make a video later this week. See you there!]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m getting ready for the presentation tomorrow at the <a href="http://www.winnipegcodecamp.com/" target="_blank">Winnipeg Code Camp</a>!</p>
<p>I&#8217;m going to talk about mocking using Rhino Mocks.</p>
<p>Here is the presentation: <a title="PDF presentation download." href="http://orthocoders.com/wp-content/uploads/2009/03/talk-the-talk-and-mock-the-mock.zip">PDF presentation download</a>.</p>
<p>I&#8217;ll try to make a video later this week.</p>
<p>See you there!</p>
]]></content:encoded>
			<wfw:commentRss>http://orthocoders.com/2009/03/14/presentation-at-winnipeg-code-camp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

