<?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>Visoft, Inc. Blogs &#187; Testing</title>
	<atom:link href="http://blogs.visoftinc.com/category/testing/feed/" rel="self" type="application/rss+xml" />
	<link>http://blogs.visoftinc.com</link>
	<description>.NET, ASP.NET, AJAX, Ruby and more</description>
	<lastBuildDate>Mon, 12 Mar 2012 18:05:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>Behavior Driven Development (BDD) with Cucumber and ASP.NET MVC</title>
		<link>http://blogs.visoftinc.com/2010/06/10/behavior-driven-development-bdd-with-cucumber-and-asp-net-mvc/</link>
		<comments>http://blogs.visoftinc.com/2010/06/10/behavior-driven-development-bdd-with-cucumber-and-asp-net-mvc/#comments</comments>
		<pubDate>Fri, 11 Jun 2010 01:18:40 +0000</pubDate>
		<dc:creator>Damien White</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Cucumber]]></category>
		<category><![CDATA[Webrat]]></category>
		<guid isPermaLink="false">/archive/2010/06/10/Behavior-Driven-Development-(BDD)-with-Cucumber-and-ASP.NET-MVC.aspx</guid>
		<description><![CDATA[So as I’m sure you have guessed by my last bunch of posts, I’ve been hooked on Ruby and Rails development.  The more I use it, the more I love it.  I felt I was loving it a bit too much, so decided to divert my attention back to ASP.NET MVC for a while.  While [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://cukes.info/" target="_blank"><img style="margin: 10px 0px 10px 20px; display: inline; border: 0px;" title="cucumber_logo" src="http://blogs.visoftinc.com/wp-content/uploads/cucumber_logo_1.png" border="0" alt="cucumber_logo" width="240" height="73" align="right" /></a> So as I’m sure you have guessed by <a href="http://blogs.visoftinc.com/category/Ruby.aspx">my last bunch of posts</a>, I’ve been hooked on Ruby and Rails development.  The more I use it, the more I love it.  I felt I was loving it a bit too much, so decided to divert my attention back to ASP.NET MVC for a while.  While developing with Rails, I was practicing BDD with <a href="http://cukes.info" target="_blank">Cucumber</a>.   I felt that Cucumber scenarios (written <a href="http://wiki.github.com/aslakhellesoy/cucumber/gherkin" target="_blank">Gherkin</a>) were far more useful for the majority of my testing on a web application.  Sure unit tests are worthwhile for bits of code, but I’ve found that they don’t always make sense when testing a web application (<a href="http://blog.stevensanderson.com/2009/11/04/selective-unit-testing-costs-and-benefits/" target="_blank">like Steve Sanderson has mentioned</a>).  Some may argue that these tests are brittle, but honestly, I feel it defines my application better and it definitely tests the actual interactions better.  I’m fully on board for unit tests for complex processes, but the majority of web work just isn’t that complex.</p>
<p>I’m not going to go fully into what BDD is here, but my goal was to use a similar process when developing ASP.NET MVC applications as I did in Rails.  With Rails, it’s simple, <a href="http://rubyonrails.org/" target="_blank">Rails</a>, <a href="http://cukes.info" target="_blank">Cucumber</a>, <a href="http://github.com/ianwhite/pickle" target="_blank">Pickle</a>, <a href="http://rails.rubyonrails.org/classes/ActiveRecord/Base.html" target="_blank">ActiveRecord</a>, <a href="http://github.com/thoughtbot/factory_girl" target="_blank">Factory Girl</a>, <a href="http://github.com/brynary/webrat" target="_blank">Webrat</a>, etc. work perfectly together.   In the .NET world, there are options, but nothing that really fit together as nicely.  I started with just wanting to test my basic application (menus, breadcrumbs, etc) and didn’t venture into model work yet, so I figured it would be as simple and efficient as it is in Rails.  Not so much.  I tweeted about this <a href="http://twitter.com/Visoft/status/12602249877" target="_blank">exact thing</a> a while ago. <span id="more-70"></span></p>
<h2>SpecFlow and WatiN</h2>
<p><a href="http://www.specflow.org/" target="_blank"><img style="margin: 10px 10px 10px 0px; display: inline; border: 0px;" title="SpecFlow Logo" src="http://blogs.visoftinc.com/wp-content/uploads/SpecFlow%20Logo_1.png" border="0" alt="SpecFlow Logo" width="244" height="100" align="left" /></a> Did I mention how much I love Cucumber?  Well, <a href="http://blogs.visoftinc.com/archive/2010/03/25/my-affair-with-ruby-on-rails.aspx#id_91faebb3-d455-471e-b42b-c452e27f58ba">Matt B</a> had recommended <a href="http://specflow.org/" target="_blank">SpecFlow</a> to me on the .NET side, so I went and started using it.  Steve Sanderson actually has a great, <a href="http://blog.stevensanderson.com/2010/03/03/behavior-driven-development-bdd-with-specflow-and-aspnet-mvc/" target="_blank">detailed post on this exact topic</a>, so I won’t go into all the things with SpecFlow.  In short, while <a href="http://specflow.org/" target="_blank">SpecFlow</a> is pretty cool and very much like <a href="http://cukes.info" target="_blank">Cucumber</a>, using it for web testing isn’t exactly great.  There are a lot of things wrong in that space, but really the thing that turned me off was the speed of the tests.  My tests are interacting with a website, and sadly there’s not much in way of web testing under .NET.  For my tests I used <a href="http://watin.sourceforge.net/" target="_blank">WatiN</a>.  WatiN is pretty cool, but the fundamental problem is that it uses the actual browser to run the test (I was using IE), and man, were my tests slow.  I had a suite of just 20 scenarios with 46 simple steps, for example, verifying the title of the page and such.  Nothing complex at all.  Running the scenarios with SpecFlow/WatiN, it takes around a <strong>minute and a half</strong> to run.  Yikes.  In my Rails project I’ve been working on, I have 167 scenarios with 1912 steps, and that takes about 2 minutes to run (and that’s running on a machine with only 2GB of RAM vs 8GB on the machine running the SpecFlow tests).  Quite a difference, not to mention the Rails tests are actually inserting things into a database as well.  The times to run these tests in .NET was just horrible, not very conducive to using BDD for these types of tests.  My hunch is that the instance of the browser was causing all of the delays in my test, and why my hunt was on for how to do my testing without using a full browser like <a href="http://github.com/brynary/webrat" target="_blank">Webrat</a> can do.</p>
<p><strong>** Update **<br />
</strong><strong>I started writing this article after just using Steve’s example as a guide, however I didn’t finish it.  I’ve been playing with other stuff, but got around to getting back to the article.  Anyway, He is using a <a href="http://github.com/SteveSanderson/GuestbookDemo/blob/master/Guestbook.Spec/Steps/Infrastructure/WebBrowser.cs" target="_blank">new browser instance for each scenario</a> (which seems like what you want so that you get a fresh instance for each scenario).  By changing the browser instance creation to be for each Feature instead, it drops the time to 30 seconds.  A bit better, but still rather slow.  Continue on for what I feel is a better option.</strong></p>
<h2>SpecFlow vs. Cucumber</h2>
<p>SpecFlow has the advantage of writing your steps in C#, but with my new found love of Ruby, I don’t have a problem whipping up steps in Ruby.  I’m not one of those people who can only use one language, and really, the steps flow much nicer in Ruby than in C#.  For example:</p>
<p>Here’s a step defined in C#:</p>
<pre class="brush: csharp;">[When("I follow \"([^\"]*)\"")]
public void WhenIFollow(string linkText)
{
    var link = WebBrowser.Current.Link(Find.ByText(linkText));
    Assert.IsNotNull(link, string.Format("Could not find a link with the text {0}", linkText));
    link.Click();
}</pre>
<p>And the Ruby version (with Webrat):</p>
<pre class="brush: ruby;">When /^I follow "([^\"]*)"$/ do |link|
  click_link(link)
end</pre>
<p>Where the <a href="http://gitrdoc.com/rdoc/brynary/webrat/b4687c29d5f5fc19e1ecfb4f24d2843b434e64ce/classes/Webrat/Scope.html#M000094" target="_blank">click_link</a> method is provided by Webrat, but they both do the same thing: follow a link on a page.  The point is the syntax, not so much what the method body looks like.  Doesn’t the Ruby look cleaner?  For example, there is no extraneous escaping needed within the regular expression, and no need for the extra method signature markup.</p>
<p>One thing that SpecFlow has is integration with Visual Studio and integration with the Unit Test runner in ReSharper and such.  That’s pretty cool, but again, I’m looking for speed in these things.</p>
<h2>Webrat and Mechanize</h2>
<p>Webrat is really designed for testing <a href="http://rack.rubyforge.org/" target="_blank">Rack</a>-based web applications, like those running on Rails or <a href="http://www.sinatrarb.com/" target="_blank">Sinatra</a>.  I previously assumed you could only use it for testing <a href="http://rack.rubyforge.org/" target="_blank">Rack</a>-based applications, but thanks to a gem called <a href="http://github.com/tenderlove/mechanize" target="_blank">Mechanize</a>, we can use Webrat with ANY website, oh yea!  Using Mechanize in Webrat is easy, it’s <a href="http://wiki.github.com/brynary/webrat/mechanize" target="_blank">just a simple change to the env.rb file</a> (typically found in the path /features/support/env.rb).  With that change, you can pretty much work with your ASP.NET MVC site just like you can with tests against Rails.  In fact, I just snagged a copy of web_steps.rb from my Rails application and the steps work just great.  The only difference is that you need to fully qualify your URIs.  Within a /features/support/paths.rb file (like you would have in Rails), I simply prefixed the relative paths with the absolute path to my local web server.  There is a <a href="http://github.com/cayblood/cucumber-webrat-mechanize-example" target="_blank">good starting project</a> from <a href="http://twitter.com/cayblood" target="_blank">@cayblood</a> on github.</p>
<p>In order to run the Cucumber tests, simply fire up a command prompt.  Then browse to the root folder where your features directory is located and it’s just a simple “cucumber” command to run all the tests.  Of course, you need to make sure your MVC web application is running or else your results are going to be very red.</p>
<h2>Big Speed Improvements</h2>
<p><img style="margin: 10px 10px 85px 20px; display: inline; border: 0px;" title="Time" src="http://blogs.visoftinc.com/wp-content/uploads/Time_1.png" border="0" alt="Time" width="204" height="137" align="right" /> So I duplicated the features in my Ruby/Cucumber/Webrat/Mechanize project (and tweak them a bit, totaling 21 scenarios and 61 steps).  Since the SpecFlow features are written in <a href="http://wiki.github.com/aslakhellesoy/cucumber/gherkin" target="_blank">Gherkin</a>, it’s easy to move the files over (just exclude the .feature.cs files from SpecFlow).  The tests took around one second to run.  That’s right… A minute and half with SpecFlow/WatiN down to a second.  Sweetness.  By the way, this is running on Windows as well where <a href="http://twitter.com/Visoft/statuses/14656975150" target="_blank">Ruby isn’t the speediest</a> (note the tests in the post were using Ruby 1.8.7 and not 1.9.1 like my tweet).</p>
<h2>Conclusion</h2>
<p>For web testing, there is just such a difference with the Ruby stack vs. the C# stack.  I would expect much better performance if there were a headless browser option available in .NET.  I don’t have any issue with using Ruby code to test C# stuff, and the more I use Ruby, the more I dislike static-typing.  I chalk it up to just “using the right tool for the job.”  Aside from using something else that isn’t C#, the second disadvantage is VS integration.  Notice I said run your tests from a command prompt.  I know you Windows guys (well most) shudder when you hear the “command line,” but <a href="http://blog.wekeroad.com/2010/04/29/visual-tooling-will-make-you-go-blind" target="_blank">some of us aren’t scared</a> :).  Personally, for the speed improvements, I can live without C# and VS integration.  Of course, here I go again, falling <a href="http://blogs.visoftinc.com/archive/2010/03/25/my-affair-with-ruby-on-rails.aspx">further in love with Ruby</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.visoftinc.com/2010/06/10/behavior-driven-development-bdd-with-cucumber-and-asp-net-mvc/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Book Review – Manning The Art of Unit Testing</title>
		<link>http://blogs.visoftinc.com/2009/09/30/book-review-manning-the-art-of-unit-testing/</link>
		<comments>http://blogs.visoftinc.com/2009/09/30/book-review-manning-the-art-of-unit-testing/#comments</comments>
		<pubDate>Wed, 30 Sep 2009 19:57:11 +0000</pubDate>
		<dc:creator>Damien White</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Review]]></category>
		<category><![CDATA[Testing]]></category>
		<guid isPermaLink="false">/archive/2009/09/30/Book-Review-Manning-The-Art-of-Unit-Testing.aspx</guid>
		<description><![CDATA[To some, “unit testing” is a four letter word.  While it’s unfortunate, the feeling is justified by poor experiences, lack of knowledge, and so on.  Personally, I’ve had mixed experiences with unit tests.  I’m sure many of you have encountered similar situations.  After reading The Art of Unit Testing by Roy Osherove, I feel far [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.amazon.com/gp/product/1933988274?ie=UTF8&amp;tag=visincblo-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=1933988274"><img style="margin: 0px 0px 5px 10px; display: inline; border-width: 0px;" title="The Art of Unit Testing" src="http://blogs.visoftinc.com/wp-content/uploads/The%20Art%20of%20Unit%20Testing.png" border="0" alt="The Art of Unit Testing" width="158" height="195" align="right" /></a>To some, “unit testing” is a four letter word.  While it’s unfortunate, the feeling is justified by poor experiences, lack of knowledge, and so on.  Personally, I’ve had mixed experiences with unit tests.  I’m sure many of you have encountered similar situations.  After reading <a href="http://www.amazon.com/gp/product/1933988274?ie=UTF8&amp;tag=visincblo-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=1933988274">The Art of Unit Testing</a><img style="margin: 0px; border-style: none !important;" src="http://www.assoc-amazon.com/e/ir?t=visincblo-20&amp;l=as2&amp;o=1&amp;a=1933988274" border="0" alt="" width="1" height="1" /> by Roy Osherove, I feel far more confident in not only understanding unit tests, but also the best practices for implementation.  If this book had only been written years ago, maybe all those poor unit testing experiences would have never happened. </p>
<p>The fundamental thing that I think is most misunderstood about unit testing is simply not understanding what a unit test is.  In fact, Roy just recently posted an updated <a href="http://weblogs.asp.net/rosherove/archive/2009/09/28/unit-test-definition-2-0.aspx" target="_blank">definition</a> of how he would classify a unit test on <a href="http://weblogs.asp.net/rosherove/default.aspx" target="_blank">his blog</a>.  Of course a definition isn’t always enough, and in his book, Roy starts off by fully explaining all the aspects of what a unit test should be and the basic outline for how to succeed.  I would highly recommend that you visit his book’s webpage (<a title="http://manning.com/osherove/" href="http://manning.com/osherove/">http://manning.com/osherove/</a>) and download the sample <a href="http://manning.com/osherove/SampleChapter1.pdf" target="_blank">first chapter</a>. </p>
<p>This seriously may be the best book ever written on unit testing.  I understand that “the best” is a strong statement, but this book is really the perfect package.  Let’s look at what makes this such a winner…</p>
<p><span id="more-21"></span></p>
<h2>Come On, The “Best”</h2>
<p>Of course, don’t just take my (or <a href="http://www.amazon.com/review/RRUL62NZ3E0CA/ref=cm_cr_rdp_perm" target="_blank">BOO’s</a>, or <a href="http://devlicio.us/blogs/tim_barcz/archive/2009/07/23/book-review-the-art-of-unit-testing.aspx" target="_blank">Tim’s</a>) word for it.  Obviously, check out other’s reviews on <a href="http://www.amazon.com/gp/product/1933988274?ie=UTF8&amp;tag=visincblo-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=1933988274">Amazon</a><img style="margin: 0px; border-style: none !important;" src="http://www.assoc-amazon.com/e/ir?t=visincblo-20&amp;l=as2&amp;o=1&amp;a=1933988274" border="0" alt="" width="1" height="1" /> as well.  However, there are many points that justify my opinion:</p>
<ul>
<li><strong>No Fluff</strong> &#8211; It’s a slimmer book (320 pages), but packed with information.  The size of the book makes it very approachable, and it’s one of those books that you may want to read a few times to make sure everything really sinks in.  It’s a book you can recommend to just about everyone, regardless of their background.</li>
<li><strong>No Preaching</strong> &#8211; One key thing that sets this book in a class by itself is the fact that it doesn’t focus on specific methodologies (like TDD), but is simply a guide to unit testing.  The book doesn’t assume anything or force any one way of practicing the art.  Fully devoted to TDD, great.  Could care less about TDD?  This book is for you as well.</li>
<li><strong>Independent</strong> – Despite the fact that Roy works for Typemock, the majority of examples found in the book use open-source “mocking” or isolation frameworks.  Throughout the book, no one tool is pushed over another.  Roy does a good job of going over the pros and cons of many different tools, from many vendors.</li>
<li><strong>Inspiring</strong> &#8211; From the initial chapter on, this book not only educates, but it truly inspires.  This is one of those books that gets you ramped up to do something.  Whether it is starting unit testing within your organization, or enhancing existing tests, you’ll want to start right away.  It’s that feeling we geeks get when a new version of software is released.  I know I’m not the only one who goes to software conferences and such, and feels like jumping head first into the latest and greatest. </li>
</ul>
<h2>Chapters</h2>
<p>This is one of the few books where each chapter matters.  Even the appendices are packed with important information.  You can see overviews of each chapter anywhere, so I won’t bore you with every little detail here.  But a few of the chapters really stood out.</p>
<ul>
<li><strong>Chapter 4, Interaction testing using mock objects</strong> – We’ve all heard the terms “mocks” and “stubs,” but do you know the difference?  Many books refer to these, but the terminology can be confusing.  After Chapter 4, you’ll have a good grip on what’s what.  The explanations and best practices in this chapter, set the base line for the rest of the chapters.  It would be nice if everyone could use the “common” definitions of things, but unfortunately, this practice isn’t always followed when it comes to discussions of unit testing. </li>
<li><strong>Chapter 8, Integrating unit testing into the organization</strong> &#8211; This topic in and of itself could be described as an “art.”  You may believe in something, but conveying the belief to others isn’t your typical walk in the park.  I was very impressed that this important issue was covered in the book. </li>
<li><strong>Chapter 9, Working with legacy code</strong> – Of course we can’t always be working on brand new development. This chapter gives a good introduction and solid approaches for dealing with legacy code.  This is another one of those chapters that’s refreshing to see within a  book of this nature.  I like how the book branched out into topics that aren’t frequently discussed.  However, this topic is really one of those that could use an entire book written about it, and Roy recommends Michael Feathers, <a href="http://www.amazon.com/gp/product/0131177052?ie=UTF8&amp;tag=visincblo-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=0131177052">Working Effectively with Legacy Code</a><img style="margin: 0px; border-style: none !important;" src="http://www.assoc-amazon.com/e/ir?t=visincblo-20&amp;l=as2&amp;o=1&amp;a=0131177052" border="0" alt="" width="1" height="1" />. Gag, legacy code, right?  It’s a reality, and remember, that new shiny thing your working on will most likely end up as someone’s headache soon enough!</li>
</ul>
<h2>More From Roy</h2>
<p>After reading his book, I immediately started seeing what else Roy has been up to.  There are two great resources that Roy started, <a href="http://5whys.com/" target="_blank">5whys.com</a> and the <a href="http://blogs.visoftinc.info/wp-admin/htt%3Cbr%20%3E%3C/a%3Ep://groups.google.com/group/leading-teams?pli=1" target="_blank">Team Leadership in Software</a> group on Google.  Both will help you in working with and leading software teams.  On the unit testing/TDD front, be sure to check out <a href="http://osherove.com/videos/" target="_blank">Roy’s videos</a>.  You can also check out Roy’s other sites, <a title="http://osherove.com/" href="http://osherove.com/" target="_blank">http://osherove.com/</a>, <a title="http://www.iserializable.com/" href="http://iserializable.com/" target="_blank">http://iserializable.com/</a>, and <a title="http://artofunittesting.com/" href="http://artofunittesting.com/" target="_blank">http://artofunittesting.com/</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blogs.visoftinc.com/2009/09/30/book-review-manning-the-art-of-unit-testing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

