<?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>Dude, where is my Kaizen? &#187; BDD</title>
	<atom:link href="http://www.bjoernrochel.de/category/testing/bdd-testing/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.bjoernrochel.de</link>
	<description>Björn Rochel&#039;s weblog</description>
	<lastBuildDate>Mon, 21 Jun 2010 07:26:00 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>xUnit.BDDExtensions now runs with xUnit 1.5 final</title>
		<link>http://www.bjoernrochel.de/2009/09/09/xunitbddextensions-now-runs-with-xunit-15-final/</link>
		<comments>http://www.bjoernrochel.de/2009/09/09/xunitbddextensions-now-runs-with-xunit-15-final/#comments</comments>
		<pubDate>Wed, 09 Sep 2009 21:25:33 +0000</pubDate>
		<dc:creator>BjRo</dc:creator>
				<category><![CDATA[xUnit]]></category>
		<category><![CDATA[xUnit.BDDExtensions]]></category>

		<guid isPermaLink="false">http://www.bjoernrochel.de/?p=551</guid>
		<description><![CDATA[I&#8217;ve just upgraded the trunk to the final 1.5 version of xUnit released last week. This update now allows BDDExtensions to be used with the latest version independant resharper runner for xUnit from xunitcontrib.
Current Version is 1.0.1.16. You can download it here or get the latest sources from the trunk.
Happy specifying . . .
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just upgraded the trunk to the final 1.5 version of xUnit released last week. This update now allows BDDExtensions to be used with the latest version independant resharper runner for xUnit from xunitcontrib.</p>
<p>Current Version is 1.0.1.16. You can download it <a href="http://xunitbddextensions.googlecode.com/files/xunit.bddextensions.1.0.1.16.zip">here</a> or get the latest sources from the <a href="http://xunitbddextensions.googlecode.com/svn/trunk/">trunk</a>.</p>
<p>Happy specifying . . .</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bjoernrochel.de/2009/09/09/xunitbddextensions-now-runs-with-xunit-15-final/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>xUnit.BDDExtensions update</title>
		<link>http://www.bjoernrochel.de/2009/09/07/xunitbddextensions-update/</link>
		<comments>http://www.bjoernrochel.de/2009/09/07/xunitbddextensions-update/#comments</comments>
		<pubDate>Mon, 07 Sep 2009 07:07:51 +0000</pubDate>
		<dc:creator>BjRo</dc:creator>
				<category><![CDATA[xUnit.BDDExtensions]]></category>

		<guid isPermaLink="false">http://www.bjoernrochel.de/?p=549</guid>
		<description><![CDATA[xUnit.BDDExtensions now uses Rhino.Mocks 3.6 internally. I&#8217;ve just updated the trunk. As usual you
can find it here: http://xunitbddextensions.googlecode.com/svn/trunk/
]]></description>
			<content:encoded><![CDATA[<p>xUnit.BDDExtensions now uses Rhino.Mocks 3.6 internally. I&#8217;ve just updated the trunk. As usual you<br />
can find it here: <a href="http://xunitbddextensions.googlecode.com/svn/trunk/" target="_blank"><tt><strong><em>http</em></strong>://xunitbddextensions.googlecode.com/svn/trunk/</tt></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.bjoernrochel.de/2009/09/07/xunitbddextensions-update/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>That&#8217;s why I like Open Source . . .</title>
		<link>http://www.bjoernrochel.de/2009/07/08/thats-why-i-like-open-source/</link>
		<comments>http://www.bjoernrochel.de/2009/07/08/thats-why-i-like-open-source/#comments</comments>
		<pubDate>Wed, 08 Jul 2009 21:19:01 +0000</pubDate>
		<dc:creator>BjRo</dc:creator>
				<category><![CDATA[xUnit.BDDExtensions]]></category>

		<guid isPermaLink="false">http://www.bjoernrochel.de/2009/07/08/thats-why-i-like-open-source/</guid>
		<description><![CDATA[Today I received a really nice feature for xUnit.BDDExtensions from a former colleague and friend of mine. It came to me completely with a spec demonstrating and documenting its usage. Completely awesome. I wish day to day software development would always be like that.   

The feature deals with chained properties on interfaces. Consider [...]]]></description>
			<content:encoded><![CDATA[<p>Today I received a really nice feature for xUnit.BDDExtensions from a former colleague and friend of mine. It came to me completely with a spec demonstrating and documenting its usage. Completely awesome. I wish day to day software development would always be like that.   </p>
<p>
The feature deals with chained properties on interfaces. Consider the following example: A presenter working against a composed passive view.  </p>
<pre class="brush: csharp">
public interface IComplexView
{
    ISubView Header {get;set;}
}  

public interface ISubView
{
    string Description {get;set;}
} 

public class Presenter
{
    private IComposedView _view;        

    public Presenter(IComposedView view)
    {
       _view = view;
    }    

    public void Initialize()
    {
       _view.Header.Description = &quot;Some caption . . .&quot;
    }
}
</pre>
<p>A spec documenting the behavior of the presenter can now look like  this if you&#8217;re using xUnit.BDDExtensions.  </p>
<pre class="brush: csharp">
[Concern(typeof(Presenter))]
public class When_the_presenter_is_initialized : InstanceContextSpecification&lt;Presenter&gt;
{
     protected override EstablishContext()
     {
          The&lt;IComposedView&gt;().HasProperties();
     }   

     protected override void Because()
     {
           Sut.Initialize();
     }     

     [Observation]
     public void It_should_set_the_headers_caption()
     {
           The&lt;IComposedView&gt;().Header.Description.ShouldBeEqualTo(&quot;Some caption . . . &quot;);
     }
}
</pre>
<p>A really large portion of the necessary glue code has been removed for that scenario. Only the HasProperties() extension method remains.  </p>
<p>Great work, Sergey. I really like the implementation of that feature . . .</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bjoernrochel.de/2009/07/08/thats-why-i-like-open-source/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>I shot me again . . .</title>
		<link>http://www.bjoernrochel.de/2009/07/07/i-shot-me-again/</link>
		<comments>http://www.bjoernrochel.de/2009/07/07/i-shot-me-again/#comments</comments>
		<pubDate>Tue, 07 Jul 2009 19:41:37 +0000</pubDate>
		<dc:creator>BjRo</dc:creator>
				<category><![CDATA[xUnit.BDDExtensions]]></category>

		<guid isPermaLink="false">http://www.bjoernrochel.de/2009/07/07/i-shot-me-again/</guid>
		<description><![CDATA[Earlier the day I wrote about my recent experience with ILMerge. As it turns out there were still some Rhino.Mocks related types which had to be excluded (The ones related to the WhenToldTo / WasToldTo functionality). This issue should be fixed now with my last check-in.    
Damn it  
]]></description>
			<content:encoded><![CDATA[<p>Earlier the day I wrote about my recent experience with ILMerge. As it turns out there were still some Rhino.Mocks related types which had to be excluded (The ones related to the WhenToldTo / WasToldTo functionality). This issue should be fixed now with my last check-in.    </p>
<p>Damn it <img src='http://www.bjoernrochel.de/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.bjoernrochel.de/2009/07/07/i-shot-me-again/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dude, I can do reports</title>
		<link>http://www.bjoernrochel.de/2009/07/05/dude-i-can-do-reports/</link>
		<comments>http://www.bjoernrochel.de/2009/07/05/dude-i-can-do-reports/#comments</comments>
		<pubDate>Sun, 05 Jul 2009 11:54:49 +0000</pubDate>
		<dc:creator>BjRo</dc:creator>
				<category><![CDATA[BDD]]></category>
		<category><![CDATA[xUnit]]></category>
		<category><![CDATA[xUnit.BDDExtensions]]></category>

		<guid isPermaLink="false">http://www.bjoernrochel.de/2009/07/05/dude-i-can-do-reports/</guid>
		<description><![CDATA[Over the past days I finally managed to spend some time with xUnit.BDDExtensions. I can&#8217;t possibly describe how good coming back to xUnit.net feels after working with MSTest in my last project. The speed, the extensibility model.&#160; It&#8217;s simply not comparable. MSTest is certainly a great tool in case you haven&#8217;t worked with a unit [...]]]></description>
			<content:encoded><![CDATA[<p>Over the past days I finally managed to spend some time with <em>xUnit.BDDExtensions</em>. I can&#8217;t possibly describe how good coming back to <em>xUnit.net</em> feels after working with <em>MSTest</em> in my last project. The speed, the extensibility model.&#160; It&#8217;s simply not comparable. <em>MSTest</em> is certainly a great tool in case you haven&#8217;t worked with a unit test framework before and it&#8217;s integration into Visual Studio is definitely a plus, too. However once you&#8217;ve got <em>Resharper</em> or <em>Gallio</em> installed the integration aspect isn&#8217;t really the big deal any more. Anyway, you can find several changes in the current trunk (<a href="http://code.google.com/p/xunitbddextensions/" target="_blank">(http://code.google.com/p/xunitbddextensions/)</a>. </p>
<h4>The biggest addition is the new ReportGenerator</h4>
<p>I&#8217;ve wanted this for quite a while now but never really found the time to implement it. After running the <em>RunBuild.cmd</em> in the &quot;Build&quot; folder of the trunk you&#8217;ll find the .exe in the &quot;Deploy&quot; folder. It&#8217;s still a bit raw but exactly what I need for my current client (yes, you heard right. <em>xUnit.BDDExtensions</em> is currently being picked up at my current client <img src='http://www.bjoernrochel.de/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> ) </p>
<p>Here are the current console arguments: </p>
<p><em>/assembly</em> configures the spec assembly to extract a report from one or more assemblies. </p>
<blockquote><p>ReportGenerator.exe /assembly:SomeSpecAssembly      <br />ReportGenerator.exe /assembly:C:\Test\SomeSpecAssembly.dll       <br />ReportGenerator.exe /assembly:&#8217;C:\Path with spaces\SomeSpecAssembly.dll&#8217; ReportGenerator.exe /assembly:SomeSpecAssembly /assembly:SomeOtherSpecAssembly</p>
</blockquote>
<p><em>/generator</em> configures the generator to use. There are currently two generators implemented. One building an ASCII .txt file which looks like <a href="http://www.bjoernrochel.de/wp-content/uploads/2009/07/xunitbddextensionsreportingspecs.txt" target="_blank">this</a>. In order to use it you have to run the generator with </p>
<blockquote><p>ReportGenerator.exe /assembly:SomeSpecAssembly /generator:Text </p>
</blockquote>
<p>The other creating an HTML file which looks like <a href="http://www.bjoernrochel.de/wp-content/uploads/2009/07/xunitbddextensionsreportingspecs.html" target="_blank">this</a>. This is the default generator which is used when you omit the <em>/generator</em> argument. </p>
<p>The files created by the generator are created on a per assembly basis and named like the assembly with the suffix .html or .txt. By default they are created in the same directory the generator is run from. </p>
<p>You can change this by configuring a different folder via <em>/path</em>. </p>
<blockquote><p>ReportGenerator.exe /assembly:C:\Test\SomeSpecAssembly.dll /path:C:\temp </p>
</blockquote>
<h3></h3>
<h4>The deployment has changed slightly</h4>
<p>The build script now merges <em>xUnit.BDDExtensions</em> to a single assembly (the external Rhino.Mocks assembly is not needed any more). Same applies to the <em>ReportGenerator</em> which uses <em>StructureMap</em> and <em>NVelocity</em> internally.    </p>
<h4>Some small changes to the API </h4>
<ul>
<li><em>Dependency&lt;TDependency&gt;()</em> has been marked as obsolete in <em>InstanceContextSpecification&lt;T&gt;</em> and <em>StaticContextSpecification</em>. </li>
<li><em>AutoDependency&lt;TDependency&gt;()</em> has been marked as obsolete in <em>InstanceContextSpecification&lt;T&gt;</em>. </li>
<li><em>An&lt;TDependency&gt;() and </em><em>Some&lt;TDependency&gt;()</em> have been added to both <em>InstanceCOntextSpecification&lt;T&gt;</em> and <em>StaticContextSpecification</em>. </li>
<li><em>The&lt;TDependency&gt;() has been added to <em>InstanceCOntextSpecification&lt;T&gt;</em></em>, </li>
</ul>
<p>Its mostly naming which has been changed. Some discussions at my current client made me realize that    <br />it&#8217;s easier to describe the behavior of xUnit.BDDExtensions to developers who haven&#8217;t used the tool before with <em>An&lt;ICar&gt;()</em> in favor of <em>Dependency&lt;ICar&gt;()</em> and <em>The&lt;ICar&gt;()</em> in favor of <em>AutoDependency&lt;ICar&gt;()</em>. </p>
<p><em>An&lt;TDependency&gt;() </em>returns a new dynamic stub object every time it&#8217;s called. <em>The&lt;TDependency&gt;()</em> behaves differently. BDDExtensions has AutoMocking support built-in. Once you let the framework create your test object you&#8217;re able to access the automatically injected dynamic stubs with this method. Last but not least <em>Some&lt;TDependency&gt;()</em> provides the same behavior as <em>An&lt;T&gt;()</em>. It only returns a collection of newly created stub objects. </p>
<p>I&#8217;m going to write a more detailed documentation of the current version soon. So in case you&#8217;re interested in the BDDExtensions, stay tuned . . . </p>
]]></content:encoded>
			<wfw:commentRss>http://www.bjoernrochel.de/2009/07/05/dude-i-can-do-reports/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Verifying indirect outputs with Rhino.Mocks in xUnit.BDDExtensions</title>
		<link>http://www.bjoernrochel.de/2009/01/30/verifying-indirect-outputs-with-rhinomocks-in-xunitbddextensions/</link>
		<comments>http://www.bjoernrochel.de/2009/01/30/verifying-indirect-outputs-with-rhinomocks-in-xunitbddextensions/#comments</comments>
		<pubDate>Fri, 30 Jan 2009 21:51:31 +0000</pubDate>
		<dc:creator>BjRo</dc:creator>
				<category><![CDATA[BDD]]></category>
		<category><![CDATA[xUnit]]></category>
		<category><![CDATA[xUnit.BDDExtensions]]></category>

		<guid isPermaLink="false">http://www.bjoernrochel.de/?p=258</guid>
		<description><![CDATA[This  post by Sean Feldman was kind of an eye opener to me. It introduced me to a feature of Rhino.Mocks I wasn&#8217;t really aware of and helped to solve a problem I was never able to solve in a really satisfying way.

As you might know xUnit.BDDExtensions is using Rhino.Mocks behind the scenes, but [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://weblogs.asp.net/sfeldman/archive/2009/01/29/factory-per-dto.aspx" target="_blank">This </a> post by Sean Feldman was kind of an eye opener to me. It introduced me to a feature of Rhino.Mocks I wasn&#8217;t really aware of and helped to solve a problem I was never able to solve in a really satisfying way.</p>
<p>
As you might know xUnit.BDDExtensions is using Rhino.Mocks behind the scenes, but hides a lot of the mechanics of the library. This was done in order to eliminate a lot of the ceremony in a specification, so that a writer of a specification could focus on its essence (Quote MASHUP from JP and Jeremy D. Miller <img src='http://www.bjoernrochel.de/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  ).  However, especially when configuring and verifying behaviors Rhino.Mocks still shines through (with all its power).
</p>
<p>So let&#8217;s take a closer look at the problem I&#8217;m referring to. It has to do with specifications which observe indirect outputs. The following code is part of a little object-to-object-mapper I wrote some months ago. </p>
<pre class="brush: csharp">
public class ExpressionBasedWriter&lt;Target, PropertyType&gt; : IWriteStrategy&lt;Target&gt;
{
	private readonly IExpressionHandler expressionHandler;
	private readonly MemberExpression memberExpression;

	public ExpressionBasedWriter(
		Expression&lt;Func&gt; memberSelector,
		IExpressionHandler expressionHandler)
	{
		this.memberExpression = (MemberExpression) memberSelector.Body;
		this.expressionHandler = expressionHandler;
	}

        public void WriteTo(Target instance, object value)
	{
		expressionHandler.Handle(new HandlerContext
                {
                      TargetInstanceType = instance.GetType(),
                      TargetInstance = instance,
                      ValueToWrite = value,
                      MemberSelector = memberExpression
                });
	}
}
</pre>
<p>
It&#8217;s not so important to understand the full context of the code. The important part is in the body of the WriteTo() method. Do you see it? It constructs an instance and passes it into an internal dependency. The interesting question now is how to verify the indirect output passed to the dependeny in a spec&#8230;
</p>
<p><strong>Take 1: Overriding Equals and GetHashcode() in the indirect output class.</strong></p>
<p>
In case you correctly implemented both of these methods you could write a spec, that looks like somewhat like this.</p>
<p><pre class="brush: csharp">
    [Concern(typeof(ExpressionBasedWriter&lt;,&gt;))]
    public class When_something_is_about_to_be_written : InstanceContextSpecification&lt;IWriteStrategy&lt;TestDto1&gt;&gt;
    {
        private IExpressionHandler expressionHandler;
        private Expression&lt;Func&gt; targetExpression;
        private TestDto1 target;
        private string valueToWrite;

        protected override void EstablishContext()
        {
            targetExpression = x =&gt; x.StringProperty;
            expressionHandler = Dependency();
            target = new TestDto1();
            valueToWrite = &quot;uninteresting value&quot;;
        }

        protected override IWriteStrategy CreateSut()
        {
            return new ExpressionBasedWriter(targetExpression, expressionHandler);
        }

        protected override void Because()
        {
            Sut.WriteTo(target, valueToWrite);
        }

        [Observation]
        public void should_form_a_context_and_pass_it_to_the_actual_expression_handler()
        {
            expressionHandler.WasToldTo(x =&gt; x.Handle(new HandlerContext
            {
                MemberSelector = (MemberExpression)targetExpression.Body,
                TargetInstance = target,
                TargetInstanceType = target.GetType(),
                ValueToWrite = valueToWrite
            }));
        }
    }
</pre>
<p>
This works. Ok, but what I don&#8217;t like about this solution is that I expose the concrete HandlerContext class to the spec. Test isolation is broken here. Besides I have to be very carefully with my implementation of Equals in this case, although it might only be needed in the specification.
</p>
<p><strong>Take 2: Introduce a factory</strong></p>
<p>
You can prevent the direct exposure of the specification to the concrete HandlerContext by introducing a factory which abstacts the creation of the HandlerContext class away.
</p>
<pre class="brush: csharp">
	public class ExpressionBasedWriter&lt;Target,PropertyType&gt; : IWriteStrategy&lt;PropertyType&gt;
	{
		private readonly IExpressionHandler expressionHandler;
		private readonly IHandlerContextFactory handleContextFactory;
		private readonly MemberExpression memberExpression;

		public ExpressionBasedWriter(
			Expression&lt;Func&gt; memberSelector,
			IExpressionHandler expressionHandler,
			IHandlerContextFactory handleContextFactory)
		{
			this.memberExpression = (MemberExpression) memberSelector.Body;
			this.expressionHandler = expressionHandler;
			this.handleContextFactory = handleContextFactory;
		}

		public void WriteTo(Target instance, object value)
		{
			var context = handleContextFactory.CreateContext(memberExpression, instance, value);
			expressionHandler.Handle(context);
		}
	}

	[Concern(typeof (ExpressionBasedWriter&lt;,&gt;))]
	public class When_something_is_about_to_be_written :
		InstanceContextSpecification&lt;IWriteStrateg&lt;TestDto1&gt;&gt;
	{
		private IExpressionHandler expressionHandler;
		private IHandlerContext handlerContext;
		private IHandlerContextFactory handlerContextFactory;
		private TestDto1 target;
		private Expression&lt;Func&gt; targetExpression;
		private string valueToWrite;

		protected override void EstablishContext()
		{
			targetExpression =  x =&gt; x.StringProperty;
			expressionHandler = Dependency();
			handlerContextFactory = Dependency();
			handlerContext = Dependency();

			target = new TestDto1();
			valueToWrite = &quot;uninteresting value&quot;;

			handlerContextFactory.WhenToldTo(x =&gt; x.CreateContext((MemberExpression)targetExpression.Body, target, valueToWrite)).Return(handlerContext);
		}

		protected override IWriteStrategy CreateSut()
		{
			return new ExpressionBasedWriter(targetExpression, expressionHandler, handlerContextFactory);
		}

		protected override void Because()
		{
			Sut.WriteTo(target, valueToWrite);
		}

		[Observation]
		public void should_call_the_context_handler_factory_in_order_to_create_a_context()
		{
			handlerContextFactory.WasToldTo(x =&gt; x.CreateContext((MemberExpression)targetExpression.Body, target, valueToWrite));
		}

		[Observation]
		public void should_call_the_expression_handler_in_order_to_handle_the_created_context()
		{
			expressionHandler.WasToldTo(x =&gt; x.Handle(handlerContext));
		}
	}
</pre>
<p>
Again, this works too. But is that really a path one should go? Introducing an additional factory + interface everytime one encounters an indirect output? Besides that, did you notice how the specification kind of degraded? So much additional noise now in there. This one causes me actually more pain than Take 1, which takes me to &#8230;
</p>
<p><strong>Take 3: A neat Rhino.Mocks feature</strong></p>
<p>
Leave the code from Take 1 as it is. Here&#8217;s how you can write the specification, without exposing it to the concrete HandlerContext class and without causing to much noise in the specification itself.
</p>
<pre class="brush: csharp">
    [Concern(typeof(ExpressionBasedWriter&lt;,&gt;))]
    public class When_something_is_about_to_be_written : InstanceContextSpecification&lt;IWriteStrategy&lt;TestDto1&gt;&gt;
    {
        private IExpressionHandler expressionHandler;
        Expression&lt;Func&gt; targetExpression;
        private TestDto1 target;
        private string valueToWrite;

        protected override void EstablishContext()
        {
            targetExpression = x =&gt; x.StringProperty;
            expressionHandler = Dependency();
            target = new TestDto1();
            valueToWrite = &quot;uninteresting value&quot;;
        }

        protected override IWriteStrategy CreateSut()
        {
            return new ExpressionBasedWriter(targetExpression, expressionHandler);
        }

        protected override void Because()
        {
            Sut.WriteTo(target, valueToWrite);
        }

        [Observation]
        public void should_form_a_context_and_pass_it_to_the_actual_expression_handler()
        {
            	expressionHandler.WasToldTo(x =&gt; x.Handle(Arg&lt;IHandlerContext&gt;.Matches(matcher =&gt;
                       matcher.MemberSelector == targetExpression.Body &amp;&amp;
                       matcher.TargetInstance == target &amp;&amp;
                       matcher.TargetInstanceType == target.GetType() &amp;&amp;
                       matcher.ValueToWrite.Equals(valueToWrite))));
        }
    }
</pre>
<p>
The interesting stuff happens around the generic Arg class. You can use it to specify a callback with which the indirect output can be verified.
</p>
<p><strong>Conclusion</strong></p>
<p>
In the past I mostly did what I demonstrated with Take 1 when I encountered a situation where I needed to verify indirect outputs. Introducing a factory for this was never really an option for me. I don&#8217;t see a real benefit there. The generic argument matching capabilities of Rhino.Mocks really close a gap for me and they&#8217;re what I&#8217;m going to use for solving similar situations from now on. </p>
<p> I hope I&#8217;m not the only kid on the street who didn&#8217;t know that this feature exists . . . </p>
]]></content:encoded>
			<wfw:commentRss>http://www.bjoernrochel.de/2009/01/30/verifying-indirect-outputs-with-rhinomocks-in-xunitbddextensions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AutoMocking in xUnit.BDDExtensions</title>
		<link>http://www.bjoernrochel.de/2009/01/26/automocking-in-xunitbddextensions/</link>
		<comments>http://www.bjoernrochel.de/2009/01/26/automocking-in-xunitbddextensions/#comments</comments>
		<pubDate>Mon, 26 Jan 2009 14:33:59 +0000</pubDate>
		<dc:creator>BjRo</dc:creator>
				<category><![CDATA[BDD]]></category>
		<category><![CDATA[xUnit]]></category>
		<category><![CDATA[xUnit.BDDExtensions]]></category>

		<guid isPermaLink="false">http://www.bjoernrochel.de/?p=248</guid>
		<description><![CDATA[
	public class when_an_automatically_resolved_instance_with_a_single_dependency_is_used_in_a_fixture :
		InstanceContextSpecification&#60;ClassWithSingleDependency&#62;
	{
		private object actualResult;
		private IDependency dependency;
		private object expectedResult;

		protected override void EstablishContext()
		{
			expectedResult = new object();
			dependency = AutoDependency&#60;IDependency&#62;();
			dependency.WhenToldTo(x =&#62; x.Invoke()).Return(expectedResult);
		}

		protected override void Because()
		{
			actualResult = Sut.Invoke();
		}

		[Observation]
		public void should_be_able_to_verify_calls_made_to_the_dependency()
		{
			dependency.WasToldTo(x =&#62; x.Invoke());
		}

		[Observation]
		public void should_execute_the_configured_behavior_on_the_dependency()
		{
			actualResult.ShouldBeEqualTo(expectedResult);
		}
	}


This little feature was added to the trunk today. Yes, no CreateSut() call. You can omit it for most of the simple scenarios. You can [...]]]></description>
			<content:encoded><![CDATA[<pre class="brush: csharp">
	public class when_an_automatically_resolved_instance_with_a_single_dependency_is_used_in_a_fixture :
		InstanceContextSpecification&lt;ClassWithSingleDependency&gt;
	{
		private object actualResult;
		private IDependency dependency;
		private object expectedResult;

		protected override void EstablishContext()
		{
			expectedResult = new object();
			dependency = AutoDependency&lt;IDependency&gt;();
			dependency.WhenToldTo(x =&gt; x.Invoke()).Return(expectedResult);
		}

		protected override void Because()
		{
			actualResult = Sut.Invoke();
		}

		[Observation]
		public void should_be_able_to_verify_calls_made_to_the_dependency()
		{
			dependency.WasToldTo(x =&gt; x.Invoke());
		}

		[Observation]
		public void should_execute_the_configured_behavior_on_the_dependency()
		{
			actualResult.ShouldBeEqualTo(expectedResult);
		}
	}
</pre>
<p />
This little feature was added to the trunk today. Yes, no CreateSut() call. You can omit it for most of the simple scenarios. You can still override it, if you need/have to. It uses the AutoMocking capabilities of StructureMap internally. </p>
<p>I&#8217;m going to merge the different involved assemblies to a single assembly soon in order to make deployment a bit easier . . . </p>
]]></content:encoded>
			<wfw:commentRss>http://www.bjoernrochel.de/2009/01/26/automocking-in-xunitbddextensions/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Why Should you?</title>
		<link>http://www.bjoernrochel.de/2009/01/23/why-should-you/</link>
		<comments>http://www.bjoernrochel.de/2009/01/23/why-should-you/#comments</comments>
		<pubDate>Fri, 23 Jan 2009 15:36:17 +0000</pubDate>
		<dc:creator>BjRo</dc:creator>
				<category><![CDATA[BDD]]></category>

		<guid isPermaLink="false">http://www.bjoernrochel.de/?p=245</guid>
		<description><![CDATA[What&#8217;s the importance of Should in BDD? Why isn&#8217;t it called Must, Need to or Will?  It&#8217;s one of those subtle psychological things . . .
The main reason Dan North decided to use Should instead of all other  possibilities is, that Should implies that you can always question the behavior of your system. It isn&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>What&#8217;s the importance of <em>Should </em>in BDD? Why isn&#8217;t it called <em>Must</em>, <em>Need to</em> or <em>Will</em>?  It&#8217;s one of those subtle psychological things . . .</p>
<p>The main reason Dan North decided to use <em>Should </em>instead of all other  possibilities is, that <em>Should </em>implies that you can always question the behavior of your system. It isn&#8217;t written in stone. If you think the system doesn&#8217;t behave correctly any more, feel free to change or drop the particular spec.</p>
<p>I found this little comment of Dan North worth remembering . . .</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bjoernrochel.de/2009/01/23/why-should-you/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wording in BDD specs</title>
		<link>http://www.bjoernrochel.de/2009/01/23/wording-in-bdd-specs/</link>
		<comments>http://www.bjoernrochel.de/2009/01/23/wording-in-bdd-specs/#comments</comments>
		<pubDate>Fri, 23 Jan 2009 15:26:48 +0000</pubDate>
		<dc:creator>BjRo</dc:creator>
				<category><![CDATA[BDD]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[xUnit.BDDExtensions]]></category>

		<guid isPermaLink="false">http://www.bjoernrochel.de/?p=221</guid>
		<description><![CDATA[Last week I had a little discussion on the german ALT.net mailing list in which I commented on a code example of a spec that wording in a BDD spec is of vital importance to BDD and therefore should be chosen very carefully. With this post I would like to clarify a bit what I [...]]]></description>
			<content:encoded><![CDATA[<p>Last week I had a little discussion on the german ALT.net mailing list in which I commented on a code example of a spec that <strong>wording in a BDD spec is of vital importance to BDD and therefore should be chosen very carefully</strong>. With this post I would like to clarify a bit what I meant with that.Â  I&#8217;d like to add that I still consider myself to be a learner in the BDD area. So, if you see things differently, feel free to comment.</p>
<p>Let&#8217;s start by looking back on my own efforts with testing and BDD. For about 2 years I wrote (what I consider to be) classical unit tests. Those tests followed strictly a &#8220;&lt;MethodName&gt;_&lt;Scenario&gt;_&lt;Behavior&gt;&#8221; naming convention originally proposed by Roy Osherove. Here&#8217;s short example of what I wrote that time.</p>
<pre class="brush: csharp">
[Fact]
public void RegisterSubscriber_NewSubscriber_SubscriberIsRegistered()
{
    var subscriber = new FakeSubscriber();

    subscriptionManager.RegisterSubscriber(subsriber);

    var wasRegistered = subscriptionManger
                                     .AllSubscriptionsFor()
                                     .Contains(subscriber);

    Assert.TruewasRegistered);
}
</pre>
<p>When changing my tests to a more BDD oriented style last august (if you&#8217;re interested why please read <a href="http://www.bjoernrochel.de/2008/08/27/first-steps-with-bdd/" target="_blank">here</a>), my style of writing tests changed to something that looked like this.</p>
<pre class="brush: csharp">
[Concern(typeof(SubscriptionManager))]
public class When_registering_a_subscriber_at_the_subscription_manager : InstanceContextSpecification
{
    ISubscriber subscriber;

    protected override void EstablishContext()
    {
        subscriber = new FakeSubscriber();
    }

    protected override SubscriptionManager CreateSut()
    {
        return new SubscriptionManager();
    }     

    protected override void Because()
    {
        Sut.RegisterSubscriber(subscriber);
    }

    [Observation]
    public void should_be_contained_in_the_list_of_subscriptions_for_the_subscribed_message()
    {
        subscriptionManger
           .AllSubscriptionsFor()
           .ShouldContain(subscriber);
    }
}
</pre>
<p>For me at that particular point BDD meant not much more than a bunch of proven practices in test design and a revised naming convention. So what might be wrong with the way the spec is written here (event in that context)?</p>
<ol>
<li>It isn&#8217;t fully refactoring safe (to be fair, the classic unit test shown above wasn&#8217;t either). Try to rename the term SubscriptionManager (or RegisterSubscriber in the first example). No refactoring tool will help you renaming your existing specs. As a consequence I would strongly suggest <strong>not to encode type or member names into a specification</strong>.</li>
<li>It doesn describe behavior. It describes implementation. A spec should describe what a system under test is supposed to do, not how it achives it.Â  Do you see the word &#8220;list&#8221; here?</li>
</ol>
<p>You could revise the spec like this.</p>
<pre class="brush: csharp">
[Concern(typeof(SubscriptionManager))]
public class When_registering_a_new_subscriber : InstanceContextSpecification
{
    ISubscriber subscriber;

    protected override void EstablishContext()
    {
        subscriber = new FakeSubscriber();
    }

    protected override SubscriptionManager CreateSut()
    {
        return new SubscriptionManager();
    }     

    protected override void Because()
    {
        Sut.RegisterSubscriber(subscriber);
    }

    [Observation]
    public void should_enable_the_subscriber_to_recieve_messages_he_is_interested_in()
    {
        subscriptionManger
           .AllSubscriptionsFor()
           .ShouldContain(subscriber);
    }
}
</pre>
<p><strong>Having said this, IS THAT THE REASON why I consider wording be to so important to BDD?</strong></p>
<p>No, not really. Nearly the same applies to classic unit testing, too.Â  We should take a closer look at BDD in order to reach the answer.</p>
<p><strong>Was the example shown above even BDD? </strong></p>
<p>IMHO Second no. The example isn&#8217;t BDD. It only shows a way how a part of BDD can be implemented, with a framework; be it xunit.bddextensions, SpecUnit, MSpec or any other tool out there.</p>
<p><strong>Ahm, ok what is BDD then?</strong></p>
<p>As I understand it so far, BDD was originally created to codify acceptance criterias of stakeholders into executable code in a way which preseverves most/all of the vocabulary the stakeholder uses. By that a shared language can be established between stakeholders.Â  (Greg Young wrote a nice post about the <a href="http://codebetter.com/blogs/gregyoung/archive/2007/10/16/bdd-and-the-shared-language.aspx" target="_self">subtle difference between BDDs shared language and DDDs ubiquitous language</a>, so I won&#8217;t repeat that here).Â  This shared language is ment to enhance the way different parties/stakeholders interact with each other, a way to enhance communication. And what is the primary utility used in the interactions between stakeholders in BDD? ==&gt; The executable specifications. &lt;==</p>
<p><strong>Coming back to why wording is so important to BDD</strong></p>
<p>What is especially interesting in BDD is, that as there&#8217;re different stakeholders, <a href="http://codebetter.com/blogs/aaron.jensen/archive/2008/10/19/bdd-consider-your-audience.aspx" target="_blank">there&#8217;re also different kind of audiences, with possibly different kind of vocabulary</a>.Â  So because BDD specs are targeted to be an acceptance criteria, they need to be written in the vocabulary of the people who will review them. This is a huge influenceÂ  besides all the more technical reasons I touched earlier which of course are relevant, too.</p>
<p>Does this make sense to you?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bjoernrochel.de/2009/01/23/wording-in-bdd-specs/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>A new syntax for xUnit.BDDExtensions ???</title>
		<link>http://www.bjoernrochel.de/2008/11/27/a-new-syntax-for-xunitbddextensions/</link>
		<comments>http://www.bjoernrochel.de/2008/11/27/a-new-syntax-for-xunitbddextensions/#comments</comments>
		<pubDate>Thu, 27 Nov 2008 13:21:51 +0000</pubDate>
		<dc:creator>BjRo</dc:creator>
				<category><![CDATA[BDD]]></category>
		<category><![CDATA[xUnit]]></category>
		<category><![CDATA[xUnit.BDDExtensions]]></category>

		<guid isPermaLink="false">http://www.bjoernrochel.de/2008/11/27/a-new-syntax-for-xunitbddextensions/</guid>
		<description><![CDATA[I&#8217;ve been doing BDD with the &#8220;context/specificationt&#8221;- style for about 4 months now.  Examples for this style are MSpec, NSpec or my little framework called xUnit.BDDExtensions.
What bothers me lately is that this style mixes context and behavior under test into one fixture class name, which can be extremely long because of that.  An [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been doing BDD with the &#8220;<a href="http://www.lostechies.com/blogs/colinjack/archive/2008/11/19/context-specification-available-frameworks-bdd.aspx" target="_blank">context/specification</a>t&#8221;- style for about 4 months now.  Examples for this style are <a href="http://codebetter.com/blogs/aaron.jensen/archive/2008/09/02/mspec-v0-2.aspx" target="_blank">MSpec</a>, <a href="http://nspec.tigris.org/" target="_blank">NSpec</a> or my little framework called <a href="http://code.google.com/p/xunitbddextensions/" target="_blank">xUnit.BDDExtensions</a>.</p>
<p>What bothers me lately is that this style mixes context and behavior under test into one fixture class name, which can be extremely long because of that.  An example to clarify what I mean:</p>
<pre class="brush: csharp"> public class When_adding_a_contact_to_a_user_with_no_existing_contacts { }
 </pre>
<p>&#8220;Adding a contact&#8221; is the observed behavior in the context of &#8220;no existing contacts&#8221;. I believe<br />
this should be more obvious, which made me thinking of how a syntax for this could look like.</p>
<p>Having said that, here is what I came up with. It&#8217;s heavily inspired by MSpec and <a href="http://dannorth.net/2007/06/introducing-rbehave" target="_blank">RBehave</a>.</p>
<pre class="brush: csharp">
[SpecificationFor(typeof(PatientService))]
public class A_patient_with_a_missing_first_name_is_not_allowed_to_be_persisted
{
      Given a_patient_with_a_missing_first_name = () =&gt;
      {
      };

      When trying_to_save_the_patient = () =&gt;
      {
      };

      It should_not_persist_the_supplied_patient = () =&gt;
      {
      };

      It should_return_a_report_indicating_that_the_patients_first_name_is_required = () =&gt;
      {
      };
}
</pre>
<p>A generated report for this code might look like this: </p>
<p><strong><span style="underline;">Specifications for &#8220;PatientService&#8221;</span></strong></p>
<ul>
<li><strong>A patient with a missing first name is not allowed to be persisted</strong>
<ul>
<li><strong>Given a patient transfer object with a missing first name</strong></li>
<li><strong>when trying to save the patient</strong>
<ul>
<li><strong>it should not persist the supplied patient</strong></li>
<li><strong>it should return a report indicating that the patients first name is required<br />
</strong></li>
</ul>
</li>
</ul>
</li>
</ul>
<p>I&#8217;m still not 100% happy with this, because there is some sort of duplication between the fixture name and the &#8220;givens&#8221; (at least in the shown example), but with this approach you</p>
<ol>
<li>are able to separate context and behavior in a clean way,</li>
<li>can describe the context very fine grained (by having multiple &#8220;givens&#8221;)</li>
<li>and besides that it looks cool <img src='http://www.bjoernrochel.de/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </li>
</ol>
<p>I would like to hear opinions on that. Is this something worth implementing / adding to xUnit.BDDExtensions?<br />
Or am I off the track with this?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.bjoernrochel.de/2008/11/27/a-new-syntax-for-xunitbddextensions/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
	</channel>
</rss>
