<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://scrum.codebetter.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Aaron Jensen</title><link>http://scrum.codebetter.com/blogs/aaron.jensen/default.aspx</link><description /><dc:language>en</dc:language><generator>CommunityServer 2007 (Build: 20416.853)</generator><item><title>Rhino.Mocks Performance Issue Fixed</title><link>http://scrum.codebetter.com/blogs/aaron.jensen/archive/2008/05/08/rhino-mocks-performance-issue-fixed.aspx</link><pubDate>Fri, 09 May 2008 05:56:15 GMT</pubDate><guid isPermaLink="false">d21fbbc9-c112-4f32-ad14-95939a2c53d4:177935</guid><dc:creator>aaronjensen</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://scrum.codebetter.com/blogs/aaron.jensen/rsscomments.aspx?PostID=177935</wfw:commentRss><comments>http://scrum.codebetter.com/blogs/aaron.jensen/archive/2008/05/08/rhino-mocks-performance-issue-fixed.aspx#comments</comments><description>&lt;p&gt;Just wanted to quickly note that I tracked down the performance issue in Rhino.Mocks and &lt;a href="http://rhino-tools.svn.sourceforge.net/viewvc/rhino-tools?view=rev&amp;amp;revision=1382"&gt;patched it&lt;/a&gt;. I also updated the &lt;a href="http://codebetter.com/blogs/aaron.jensen/archive/2008/05/08/mock-framework-benchmarks.aspx"&gt;original post&lt;/a&gt; with the new numbers. Enjoy!&lt;/p&gt;&lt;img src="http://scrum.codebetter.com/aggbug.aspx?PostID=177935" width="1" height="1"&gt;</description><category domain="http://scrum.codebetter.com/blogs/aaron.jensen/archive/tags/frameworks/default.aspx">frameworks</category><category domain="http://scrum.codebetter.com/blogs/aaron.jensen/archive/tags/mocking/default.aspx">mocking</category></item><item><title>Mock Framework Benchmarks</title><link>http://scrum.codebetter.com/blogs/aaron.jensen/archive/2008/05/08/mock-framework-benchmarks.aspx</link><pubDate>Thu, 08 May 2008 15:50:50 GMT</pubDate><guid isPermaLink="false">d21fbbc9-c112-4f32-ad14-95939a2c53d4:177893</guid><dc:creator>aaronjensen</dc:creator><slash:comments>9</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://scrum.codebetter.com/blogs/aaron.jensen/rsscomments.aspx?PostID=177893</wfw:commentRss><comments>http://scrum.codebetter.com/blogs/aaron.jensen/archive/2008/05/08/mock-framework-benchmarks.aspx#comments</comments><description>&lt;strong&gt;UPDATE: I tracked down the issue and committed a patch to Rhino.Mocks. Rhino.Mocks is now much more competetive performance wise, our CI build time nearly halved, and about 4 minutes out of 7 of our test time has disappeared. New numbers below.&lt;/strong&gt;   &lt;p&gt;I&amp;#39;ve complained before that &lt;a href="http://blog.eleutian.com/2007/12/15/MockingIsSlow.aspx"&gt;Mocking is Slow&lt;/a&gt; but I never really dove further into it. Today I decided to actually compare Rhino.Mocks to other mock frameworks on a pure performance basis to see if it was a global problem. I timed 2000 unit tests across 100 classes with 20 tests each. The results were a bit surprising:&lt;/p&gt;  &lt;table&gt;     &lt;tr&gt;       &lt;th&gt;Framework&lt;/th&gt;        &lt;th&gt;&lt;a href="http://testdriven.net/"&gt;TD.NET&lt;/a&gt; Time&lt;/th&gt;        &lt;th&gt;nunit-console Time&lt;/th&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td&gt;&lt;a href="http://www.ayende.com/projects/rhino-mocks.aspx"&gt;Rhino.Mocks&lt;/a&gt; old trunk&lt;/td&gt;        &lt;td&gt;57.36s&lt;/td&gt;        &lt;td&gt;28.82s&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td&gt;&lt;a href="http://www.ayende.com/projects/rhino-mocks.aspx"&gt;Rhino.Mocks&lt;/a&gt; new trunk&lt;/td&gt;        &lt;td&gt;22.94s&lt;/td&gt;        &lt;td&gt;7.59s&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td&gt;&lt;a href="http://code.google.com/p/moq/"&gt;Moq&lt;/a&gt; trunk&lt;/td&gt;        &lt;td&gt;18.30s&lt;/td&gt;        &lt;td&gt;5.91s&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td&gt;&lt;a href="http://www.typemock.com/"&gt;TypeMock&lt;/a&gt; 4.2.3 Reflective Mocks&lt;/td&gt;        &lt;td&gt;15.36s&lt;/td&gt;        &lt;td&gt;9.35s&lt;/td&gt;     &lt;/tr&gt;      &lt;tr&gt;       &lt;td&gt;&lt;a href="http://www.typemock.com/"&gt;TypeMock&lt;/a&gt; 4.2.3 Natural Mocks&lt;/td&gt;        &lt;td&gt;16.92s&lt;/td&gt;        &lt;td&gt;9.56s&lt;/td&gt;     &lt;/tr&gt;   &lt;/table&gt;  &lt;p&gt;That&amp;#39;s right, according to these tests, &lt;a href="http://www.ayende.com/projects/rhino-mocks.aspx"&gt;Rhino.Mocks&lt;/a&gt; is at least 3 times slower than the other frameworks when under heavy load in TD.NET and five times slower in the console according to these tests. It&amp;#39;s also interesting to note that &lt;a href="http://www.typemock.com/"&gt;TypeMock&lt;/a&gt; is faster than &lt;a href="http://code.google.com/p/moq/"&gt;Moq&lt;/a&gt; in TD.NET, but slower in the console runner.&lt;/p&gt;  &lt;p&gt;While running the Rhino.Mocks tests it is very clear that there is a degrading performance issue. All the other frameworks executed tests with a near constant speed per test, but Rhino.Mocks slowed down noticeably about half way through.&lt;/p&gt;  &lt;p&gt;Please feel free to try it yourself, grab the project &lt;a href="http://blog.eleutian.com/download/BenchMock.zip"&gt;here&lt;/a&gt;. You should be able to just run the 4 strategy .bat files (run-rhino, run-moq, run-tmock-reflective, run-tmock-natural). Let me know if you find anything interesting.&lt;/p&gt;&lt;img src="http://scrum.codebetter.com/aggbug.aspx?PostID=177893" width="1" height="1"&gt;</description><category domain="http://scrum.codebetter.com/blogs/aaron.jensen/archive/tags/frameworks/default.aspx">frameworks</category><category domain="http://scrum.codebetter.com/blogs/aaron.jensen/archive/tags/mocking/default.aspx">mocking</category></item><item><title>Introducing Machine.Specifications (or MSpec for short)</title><link>http://scrum.codebetter.com/blogs/aaron.jensen/archive/2008/05/08/introducing-machine-specifications-or-mspec-for-short.aspx</link><pubDate>Thu, 08 May 2008 07:12:19 GMT</pubDate><guid isPermaLink="false">d21fbbc9-c112-4f32-ad14-95939a2c53d4:177858</guid><dc:creator>aaronjensen</dc:creator><slash:comments>7</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://scrum.codebetter.com/blogs/aaron.jensen/rsscomments.aspx?PostID=177858</wfw:commentRss><comments>http://scrum.codebetter.com/blogs/aaron.jensen/archive/2008/05/08/introducing-machine-specifications-or-mspec-for-short.aspx#comments</comments><description>&lt;p&gt;As some of you who follow &lt;a href="http://twitter.com/aaronjensen"&gt;me on twitter&lt;/a&gt; know, I&amp;#39;ve been working on Yet Another Context/Specification Framework as an experiment. Yeah, I know we already have &lt;a href="http://nspec.tigris.org/"&gt;NSpec&lt;/a&gt; and &lt;a href="http://nbehave.org/"&gt;NBehave&lt;/a&gt;, and they&amp;#39;re great and all, but MSpec takes things on from a slightly different angle, and it&amp;#39;s just an experiment (for now). Here&amp;#39;s a sample Description:&lt;/p&gt;  &lt;pre name="code" class="c-sharp"&gt;[Description]
public class Transferring_between_from_account_and_to_account
{
  static Account fromAccount;
  static Account toAccount;

  Context before_each =()=&amp;gt;
  {
    fromAccount = new Account {Balance = 1m};
    toAccount = new Account {Balance = 1m};
  };
  
  When the_transfer_is_made =()=&amp;gt;
  {
    fromAccount.Transfer(1m, toAccount);
  };
   
  It should_debit_the_from_account_by_the_amount_transferred =()=&amp;gt;
  {
    fromAccount.Balance.ShouldEqual(0m);
  };

  It should_credit_the_to_account_by_the_amount_transferred =()=&amp;gt;
  {
    toAccount.Balance.ShouldEqual(2m);
  };
}&lt;/pre&gt;

&lt;p&gt;And a TestDriven.NET run:&lt;/p&gt;

&lt;pre&gt;------ Test started: Assembly: Machine.Specifications.Example.dll ------

Transferring between from account and to account
  When the transfer is made
    * It should debit the from account by the amount transferred
    * It should credit the to account by the amount transferred


2 passed, 0 failed, 0 skipped, took 0.79 seconds.&lt;/pre&gt;

&lt;h3&gt;Err, What?&lt;/h3&gt;

&lt;p&gt;Different eh? The idea was heavily inspired by &lt;a href="http://twitter.com/sbellware"&gt;Scott Bellware&lt;/a&gt;&amp;#39;s SpecUnit.Net framework he showed at the ALT.NET conference. It also took heavy cues from &lt;a href="http://rspec.info/"&gt;RSpec&lt;/a&gt; and my insanity. I realize that the the code doesn&amp;#39;t look much like C# code and I&amp;#39;m OK with that. Many have and will ask why I don&amp;#39;t just use Boo or RSpec w/ IronRuby eventually or even one of the existing Context/Spec/BDD frameworks. Those are good questions, but my main motivations are tooling and syntax. I enjoy the tooling I get in C# and I personally like the syntax in this library considering the limitations imposed by C#.&lt;/p&gt;

&lt;h3&gt;How&amp;#39;s it work?&lt;/h3&gt;

&lt;p&gt;The simplest way to describe it is to compare it to a normal *Unit style testing framework: &lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Description = TestContext &lt;/li&gt;

  &lt;li&gt;Context before_each = SetUp &lt;/li&gt;

  &lt;li&gt;Context before_all = SetUpFixture &lt;/li&gt;

  &lt;li&gt;Context after_each = TearDown &lt;/li&gt;

  &lt;li&gt;Context after_all = TearDownFixture &lt;/li&gt;

  &lt;li&gt;When = Also SetUp, but happens after Context before_each &lt;/li&gt;

  &lt;li&gt;It = Test &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Rather than methods and attributes, MSpec uses named delegates and anonymous functions. The only reason for this is readability. You&amp;#39;ll also notice that the fields used in the context are static. This is necessary so that the anonymous functions in the field initializers can access them. Probably the first thing you noticed is the =()=&amp;gt; construct. I won&amp;#39;t mention the names that this was given on twitter, but I think it&amp;#39;s an acceptable thing to have to deal with in exchange for the cleanliness of the rest of the syntax.&lt;/p&gt;

&lt;h3&gt;Ok, you&amp;#39;re crazy, but how do I try it?&lt;/h3&gt;

&lt;p&gt;First, this is a very rough cut. Everything is subject to change as we experiment with the language. That said, here&amp;#39;s how you play with it:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Grab the drop &lt;a href="http://blog.eleutian.com/download/mspec-0.1.zip"&gt;here&lt;/a&gt;. &lt;/li&gt;

  &lt;li&gt;Extract it somewhere. Put it somewhere semi-permanent because the &lt;a href="http://testdriven.net/"&gt;TestDriven.NET&lt;/a&gt; runner will need a static location for the MSpec TDNet Runner. &lt;/li&gt;

  &lt;li&gt;If you want TestDriven.NET support, run &lt;strong&gt;InstallTDNetRunner.bat&lt;/strong&gt; &lt;/li&gt;

  &lt;li&gt;Check out the example in &lt;strong&gt;Machine.Specifications.Example&lt;/strong&gt;. Note that you can run with TD.NET. &lt;/li&gt;

  &lt;li&gt;Create a project of your own. Just add &lt;strong&gt;Machine.Specifications.dll&lt;/strong&gt; and get started. &lt;/li&gt;

  &lt;li&gt;Send me feedback! Leave comments, email me, &lt;a href="http://twitter.com/aaronjensen"&gt;tweet me&lt;/a&gt;, whatever. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Also, this is part of &lt;a href="http://www.assembla.com/wiki/show/machine"&gt;Machine&lt;/a&gt;, so feel free to take a &lt;a href="http://svn2.assembla.com/svn/machine/trunk/"&gt;look at the code&lt;/a&gt; and/or submit patches. There&amp;#39;s also a &lt;a href="http://www.gallio.org/"&gt;Gallio&lt;/a&gt; adapter in there, but I didn&amp;#39;t include it in the release as it&amp;#39;s not quite polished enough yet. If you&amp;#39;re interested in it, talk to me. Special thanks to &lt;a href="http://twitter.com/sbellware"&gt;Scott Bellware&lt;/a&gt;, &lt;a href="http://blog.bits-in-motion.com/"&gt;Jeff Brown&lt;/a&gt; and &lt;a href="http://weblogs.asp.net/nunitaddin/default.aspx"&gt;Jamie Cansdale&lt;/a&gt; for their help and support.&lt;/p&gt;&lt;img src="http://scrum.codebetter.com/aggbug.aspx?PostID=177858" width="1" height="1"&gt;</description><category domain="http://scrum.codebetter.com/blogs/aaron.jensen/archive/tags/bdd/default.aspx">bdd</category><category domain="http://scrum.codebetter.com/blogs/aaron.jensen/archive/tags/frameworks/default.aspx">frameworks</category><category domain="http://scrum.codebetter.com/blogs/aaron.jensen/archive/tags/machine/default.aspx">machine</category></item><item><title>Mocking Events</title><link>http://scrum.codebetter.com/blogs/aaron.jensen/archive/2008/04/13/mocking-events.aspx</link><pubDate>Sun, 13 Apr 2008 08:29:51 GMT</pubDate><guid isPermaLink="false">d21fbbc9-c112-4f32-ad14-95939a2c53d4:176640</guid><dc:creator>aaronjensen</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://scrum.codebetter.com/blogs/aaron.jensen/rsscomments.aspx?PostID=176640</wfw:commentRss><comments>http://scrum.codebetter.com/blogs/aaron.jensen/archive/2008/04/13/mocking-events.aspx#comments</comments><description>&lt;p&gt;Currently in Rhino.Mocks, making mocks fire events and ensuring that an event on your SUT was fired are both awkward and verbose at best. Here is an example of both things at once:&lt;/p&gt;  &lt;pre class="c-sharp" name="code"&gt;[Test]
public void ViewFiresBeginDrag_Always_FiresChangedEvent()
{
  IEventRaiser raiser;
  bool eventFired = false;
  using (Record)
  {
    The&amp;lt;ICardView&amp;gt;().BeginDrag += null;
    raiser = LastCall.IgnoreArguments().GetEventRaiser();

    Target.Changed += (x,y) =&amp;gt; eventFired = true;
  }

  using (Playback)
  {
    raiser.Raise(The&amp;lt;ICardView&amp;gt;(), EventArgs.Empty);
    Assert.IsTrue(eventFired);
  }
}&lt;/pre&gt;

&lt;p&gt;Nice eh? First, is there a better way to do either of these things that I&amp;#39;m missing? Please tell me if so. Next, if not, what can we do to clean this up?&lt;/p&gt;

&lt;p&gt;Well, Ayende and I &lt;a href="http://www.ayende.com/Blog/archive/2007/06/09/Rhino-Mocks-Events-Twisting-the-Syntax.aspx"&gt;discussed this&lt;/a&gt; in the past and Ayende spiked it and &lt;a href="http://www.ayende.com/Blog/archive/2007/06/23/Natural-Event-Syntax-for-Rhino-Mocks.aspx"&gt;asked for feedback&lt;/a&gt;. The feedback was mixed and for one reason or another it never made it into Rhino.Mocks that I know of.&lt;/p&gt;

&lt;p&gt;Well, today while I was working on &lt;a href="http://svn2.assembla.com/svn/machine/trunk/Machine.Testing/"&gt;Machine.Testing&lt;/a&gt; and another side project, I decided to give something else a shot. What I ended up with is this:&lt;/p&gt;

&lt;pre class="c-sharp" name="code"&gt;[Test]
public void ViewFiresBeginDrag_Always_FiresChangedEvent()
{
  using (Record)
  {
    PrimeEventFiringOn&amp;lt;ICardView&amp;gt;(x =&amp;gt; x.BeginDrag += null);
    Target.Changed += NewEventFireExpectation&amp;lt;EventHandler&amp;gt;();
  }

  using (Playback)
  {
    FireEventOn&amp;lt;ICardView&amp;gt;(EventArgs.Empty);
  }
}&lt;/pre&gt;

&lt;p&gt;Better, but I still don&amp;#39;t think it&amp;#39;s perfect. Also, it probably requires some explanation, so let&amp;#39;s pick it apart piece by piece:&lt;/p&gt;

&lt;pre class="c-sharp" name="code"&gt;    PrimeEventFiringOn&amp;lt;ICardView&amp;gt;(x =&amp;gt; x.BeginDrag += null);&lt;/pre&gt;

&lt;p&gt;=&amp;gt; +=??? Ugly huh? I really wish we could just refer to an event somehow without having to do +=/-=. At least I&amp;#39;m &lt;a href="http://twitter.com/jbogard/statuses/788133552"&gt;not using vb though&lt;/a&gt;... Alas, we cannot access them easily so we&amp;#39;re stuck hacking away like this. So this particular method will basically get the mock or stub ICardView.BeginDrag ready to be fired. This needs to be done during the record phase it seems. You can only prime one event at a time per mock, so if you need to do more than one you can revert to the normal Rhino.Mocks syntax.&lt;/p&gt;

&lt;pre class="c-sharp" name="code"&gt;    Target.Changed += NewEventFireExpectation&amp;lt;EventHandler&amp;gt;();&lt;/pre&gt;

&lt;p&gt;This was a fun method. This method actually creates a new DynamicMethod in the signature required by the event and creates a new delegate. The method tracks whether or not it was fired, and at the end of the Playback phase in my fixture it will assert that all of the events were actually fired.&lt;/p&gt;

&lt;pre class="c-sharp" name="code"&gt;    FireEventOn&amp;lt;ICardView&amp;gt;(EventArgs.Empty);&lt;/pre&gt;

&lt;p&gt;This actually fires the event we set up in the Prime call. It can only be called after you&amp;#39;ve primed an event.&lt;/p&gt;

&lt;p&gt;So, the whole thing is kind of &amp;quot;magic&amp;quot;, but it&amp;#39;s less code if you can accept the magic. I think we can make things even better though, but it&amp;#39;d require changes to Rhino.Mocks and it&amp;#39;s time for bed so maybe Ayende can swing by the Eleutian office while in Seattle and we can work on it. Here&amp;#39;s what I&amp;#39;m thinking:&lt;/p&gt;

&lt;pre class="c-sharp" name="code"&gt;[Test]
public void ViewFiresBeginDrag_Always_FiresChangedEvent()
{
  using (Record)
  {
    Target.Changed += Mocks.CreateEventHandler&amp;lt;EventHandler&amp;gt;();
  }

  using (Playback)
  {
    EventRaiser.Raise(() =&amp;gt; The().BeginDrag += null, The&amp;lt;ICardView&amp;gt;(), EventArgs.Empty);
  }
}&lt;/pre&gt;

&lt;p&gt;There&amp;#39;s probably more you can do with the CreateEventHandler syntax like add more specific expectations, assert its not fired, assert that it&amp;#39;s fired X times, etc. The EventRaiser syntax is ugly, but it doesn&amp;#39;t involve strings or the fire from the right hand side like the syntax I mentioned at the beginning of the post.&lt;/p&gt;

&lt;p&gt;You can get the source &lt;a href="http://svn2.assembla.com/svn/machine/trunk/Machine.Testing/"&gt;here&lt;/a&gt;, but I warn you it&amp;#39;s first draft and there are hacky bits.&lt;/p&gt;

&lt;p&gt;Oh, and here&amp;#39;s some example tests using the TestsFor fixture:&lt;/p&gt;

&lt;pre class="c-sharp" name="code"&gt;[TestFixture]
public class CardPresenterTests : TestsFor&amp;lt;CardPresenter&amp;gt;
{
  private Card _card;

  public override void SetupContainer()
  {
    Override&amp;lt;ICardView&amp;gt;(With.Stub);
  }

  public override void BeforeEachTest()
  {
    _card = new Card(0);
  }

  [Test]
  public void OnBeginDrag_Always_SetsIsInFluxToTrue()
  {
    using (Record)
    {
      PrimeEventFiringOn&amp;lt;ICardView&amp;gt;(x =&amp;gt; x.BeginDrag += null);
    }

    using (Playback)
    {
      FireEventOn(EventArgs.Empty);

      Assert.That(The&amp;lt;ICardView&amp;gt;().IsInFlux, Is.True);
    }
  }

  [Test]
  public void OnBeginDrag_Always_FiresChangedEvent()
  {
    using (Record)
    {
      PrimeEventFiringOn&amp;lt;ICardView&amp;gt;(x =&amp;gt; x.BeginDrag += null);
      Target.Changed += NewEventFireExpectation&amp;lt;EventHandler&amp;gt;();
    }

    using (Playback)
    {
      FireEventOn&amp;lt;ICardView&amp;gt;(EventArgs.Empty);
    }
  }
}&lt;/pre&gt;&lt;img src="http://scrum.codebetter.com/aggbug.aspx?PostID=176640" width="1" height="1"&gt;</description><category domain="http://scrum.codebetter.com/blogs/aaron.jensen/archive/tags/frameworks/default.aspx">frameworks</category><category domain="http://scrum.codebetter.com/blogs/aaron.jensen/archive/tags/mocking/default.aspx">mocking</category></item><item><title>Book Review: Hacking Vim</title><link>http://scrum.codebetter.com/blogs/aaron.jensen/archive/2008/04/09/book-review-hacking-vim.aspx</link><pubDate>Thu, 10 Apr 2008 05:01:41 GMT</pubDate><guid isPermaLink="false">d21fbbc9-c112-4f32-ad14-95939a2c53d4:176555</guid><dc:creator>aaronjensen</dc:creator><slash:comments>2</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://scrum.codebetter.com/blogs/aaron.jensen/rsscomments.aspx?PostID=176555</wfw:commentRss><comments>http://scrum.codebetter.com/blogs/aaron.jensen/archive/2008/04/09/book-review-hacking-vim.aspx#comments</comments><description>&lt;a href="http://www.amazon.com/gp/product/1847190936?ie=UTF8&amp;amp;tag=elespedevblo-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=1847190936"&gt;&lt;img src="http://ecx.images-amazon.com/images/I/41RDKEUKfrL._SL500_AA240_.jpg" align="right" border="0" alt="" /&gt;&lt;/a&gt;   &lt;p&gt;Some time ago, &lt;a href="http://www.packtpub.com/"&gt;Packt Publishing&lt;/a&gt; sent me a copy of &lt;a href="http://www.amazon.com/gp/product/1847190936?ie=UTF8&amp;amp;tag=elespedevblo-20&amp;amp;linkCode=as2&amp;amp;camp=1789&amp;amp;creative=9325&amp;amp;creativeASIN=1847190936"&gt;Hacking Vim: A Cookbook to get the Most out of the Latest Vim Editor&lt;/a&gt;&lt;img style="margin:0px;" height="1" alt="" src="http://www.assoc-amazon.com/e/ir?t=elespedevblo-20&amp;amp;l=as2&amp;amp;o=1&amp;amp;a=1847190936" width="1" border="0" /&gt; by Kim Shulz to review. I read through it pretty quickly and I must say I thought it was a good book for the most part. The book is definitely focused at a very niche audience as there aren&amp;#39;t a lot of us Vimmers around. Furthermore, I can&amp;#39;t say I&amp;#39;d recommend the book for the casual Vimmer or those that use only &lt;a href="http://www.plimus.com/jsp/redirect.jsp?contractId=1723786&amp;amp;referrer=aaronjensen"&gt;ViEmu&lt;/a&gt; in Visual Studio. If, however, you are a moderate to hardcore Vim user or are interested in becoming one I would definitely recommend grabbing a copy.&lt;/p&gt;  &lt;p&gt;There is a &lt;strong&gt;lot&lt;/strong&gt; of information in this book. It wastes no time or space describing the many ways to make your Vim experience even more efficient than it already is. Because of its very cut and dry style it reads more like a reference book than anything else, but I think that&amp;#39;s perfectly fine for this style of book. It is essentially a slightly more readable, more detailed and better written version of a lot of the Vim help. It&amp;#39;s also nice because in many of the chapters, especially the first few (&amp;quot;Better Navigation&amp;quot; and &amp;quot;Production Boosters&amp;quot;) you can pick up a lot of interesting tips. I even learned a few handy commands I had no idea about.&lt;/p&gt;  &lt;p&gt;There&amp;#39;s plenty of good information on writing Vim plugins and customizing Vim that I wish I would have had six years back when &lt;a href="http://vim.sourceforge.net/scripts/script.php?script_id=481"&gt;I wrote Vim plugins&lt;/a&gt;. Ah, looking at that code brings back fond memories, mostly involving learning Regular Expressions through trial and error and I actually used /// comments in C# code, but I digress. &lt;/p&gt;  &lt;p&gt;I also liked the stuff on firing Ruby from Vim--it reminded me I need to get a Ruby environment set up in Vim. Oh, and just for fun it seems, Kim even included an appendix showcasing some of the ridiculous things that have been written for Vim like &lt;a href="http://vim.sourceforge.net/scripts/script.php?script_id=916"&gt;Nibbles&lt;/a&gt; and &lt;a href="http://vim.sourceforge.net/scripts/script.php?script_id=1217"&gt;Rubik&amp;#39;s Cube&lt;/a&gt;. Heck, I just found a &lt;a href="http://vim.sourceforge.net/scripts/script.php?script_id=2204"&gt;Twitter client&lt;/a&gt; for Vim (yea, I &lt;a href="http://twitter.com/aaronjensen"&gt;twitter now&lt;/a&gt; in case you care).&lt;/p&gt;  &lt;p&gt;There are a few things wrong with it though. Some things are too close to the Vim built-in help and you&amp;#39;re probably better off just looking there. Also, the index isn&amp;#39;t very useful and it&amp;#39;d be nice to have a searchable version of the book as well, so maybe the &lt;a href="http://www.packtpub.com/Vim/book"&gt;eBook version&lt;/a&gt; is a good idea. I wish all book companies would bundle eBooks with paper books, but, I digress again. Like I said, there is a lot of information in this book. It&amp;#39;s not for everyone, but I think most Vim users will find plenty of useful stuff in its pages. &lt;/p&gt;&lt;img src="http://scrum.codebetter.com/aggbug.aspx?PostID=176555" width="1" height="1"&gt;</description><category domain="http://scrum.codebetter.com/blogs/aaron.jensen/archive/tags/featured/default.aspx">featured</category><category domain="http://scrum.codebetter.com/blogs/aaron.jensen/archive/tags/reviews/default.aspx">reviews</category><category domain="http://scrum.codebetter.com/blogs/aaron.jensen/archive/tags/vim/default.aspx">vim</category></item><item><title>Separate Stub and Verify != Duplicate code necessarily</title><link>http://scrum.codebetter.com/blogs/aaron.jensen/archive/2008/04/03/separate-stub-and-verify-duplicate-code-necessarily.aspx</link><pubDate>Thu, 03 Apr 2008 16:43:00 GMT</pubDate><guid isPermaLink="false">d21fbbc9-c112-4f32-ad14-95939a2c53d4:176276</guid><dc:creator>aaronjensen</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://scrum.codebetter.com/blogs/aaron.jensen/rsscomments.aspx?PostID=176276</wfw:commentRss><comments>http://scrum.codebetter.com/blogs/aaron.jensen/archive/2008/04/03/separate-stub-and-verify-duplicate-code-necessarily.aspx#comments</comments><description>&lt;p&gt;&lt;a href="http://www.clariusconsulting.net/kzu"&gt;Daniel Cazzulino&lt;/a&gt;, author of Moq posted a good comment on my last post where I suggested looking into a Mockito like syntax for .NET Mock Frameworks.&lt;/p&gt; &lt;p&gt;&lt;em&gt;On the surface, Mockito&amp;#39;s approach seems good. But if you do the &amp;quot;true&amp;quot; comparison, you&amp;#39;ll see that stub(...) is exactly the same as mock.Expect(...) in Moq.&lt;/em&gt;&lt;/p&gt; &lt;p&gt;&lt;em&gt;Then, when you do verify(...), you have to basically repeat the exact same expression you put in stub(...). This might work if you only have a couple calls to verify, but for anything else, it will be a lot of repeated code, I&amp;#39;m afraid. &lt;/em&gt;&lt;/p&gt; &lt;p&gt;I thought this too. See my comment &lt;a href="http://monkeyisland.pl/2008/02/24/can-i-test-what-i-want-please/#comments"&gt;here&lt;/a&gt; from a month ago. &lt;a href="http://monkeyisland.pl/"&gt;Szczepan&lt;/a&gt; made a good point and I&amp;#39;ve thought about it more since then.&lt;/p&gt; &lt;p&gt;When combined with my position on loose vs strict mocks (almost always use loose), I&amp;#39;d say that *most* of the time you are either stubbing or verifying. Meaning, if you&amp;#39;re verifying you don&amp;#39;t need to stub unless of course that method returns something that is critical to the flow of your test, in which case you don&amp;#39;t really need to verify, because the flow would have verified. That&amp;#39;s a mouthful, but does that make sense?&lt;/p&gt; &lt;p&gt;I haven&amp;#39;t used mockito, and I know there are times I use Expect.Call with return values that matter (which would essentially require you to duplicate stub &amp;amp; verify), but maybe that&amp;#39;s a smell? Maybe if you think you need that you can do state based testing or change your API?&lt;/p&gt; &lt;p&gt;Here&amp;#39;s an example Test using Rhino.Mocks:&lt;/p&gt;&lt;pre class="c-sharp" name="code"&gt;[Test]
public void SomeMethod_Always_CallsSendMail()
{
  IMailSender sender = mocks.DynamicMock();
  UnderTest underTest = new UnderTest(sender);

  using (mocks.Record())
  {
    Expect.Call(sender.SendMail()).Returns(true);
  }

  underTest.SomeMethod();

  mocks.Verify(sender);
}&lt;/pre&gt;
&lt;p&gt;And some code this is testing (obviously not test driven, but you get the idea):&lt;/p&gt;&lt;pre class="c-sharp" name="code"&gt;public void SomeMethod()
{
  if (!_sender.SendMail())
  {
    throw new Exception(&amp;quot;OH NOS&amp;quot;);
  }
}&lt;/pre&gt;
&lt;p&gt;Notice that here we would need to stub and verify separately with Mockito like syntax. This would look something like this:&lt;/p&gt;&lt;pre class="c-sharp" name="code"&gt;[Test]
public void SomeMethod_Always_CallsSendMail()
{
  IMailSender sender = mocks.DynamicMock();
  UnderTest underTest = new UnderTest(sender);

  Stub.That(() =&amp;gt; sender.SendMail()).Returns(true);

  underTest.SomeMethod();

  Verify.That(() =&amp;gt; sender.SendMail()).WasCalled();
}&lt;/pre&gt;
&lt;p&gt;This may violate DRY, but what if you designed your API differently? Maybe SendMail should throw an exception on failure instead of returning a boolean? This would make the return value unnecessary and remove the need for the Stub call. Clearly you can&amp;#39;t always do this, especially with unwrapped legacy or API code, but it&amp;#39;s something to think about.&lt;/p&gt;
&lt;p&gt;Also, I think you shouldn&amp;#39;t be verifying more than one method generally to go along with the one assert/test rule, so a single repeat would not be that horrendous. Heck, you could even do:&lt;/p&gt;&lt;pre class="c-sharp" name="code"&gt;[Test]
public void SomeMethod_Always_CallsSendMail()
{
  IMailSender sender = mocks.DynamicMock();
  UnderTest underTest = new UnderTest(sender);

  Stub.That(var sendMail = () =&amp;gt; sender.SendMail()).Returns(true);

  underTest.SomeMethod();

  Verify.That(sendMail).WasCalled();
}&lt;/pre&gt;
&lt;p&gt;I think the syntax would lead to better, more concise tests. But maybe it would just be too annoying? I wouldn&amp;#39;t know until I tried it for a while I guess.&lt;/p&gt;&lt;img src="http://scrum.codebetter.com/aggbug.aspx?PostID=176276" width="1" height="1"&gt;</description><category domain="http://scrum.codebetter.com/blogs/aaron.jensen/archive/tags/frameworks/default.aspx">frameworks</category><category domain="http://scrum.codebetter.com/blogs/aaron.jensen/archive/tags/mocking/default.aspx">mocking</category></item><item><title>The Past, Present and Future (?) of Mocking</title><link>http://scrum.codebetter.com/blogs/aaron.jensen/archive/2008/04/02/the-past-present-and-future-of-mocking.aspx</link><pubDate>Thu, 03 Apr 2008 04:12:26 GMT</pubDate><guid isPermaLink="false">d21fbbc9-c112-4f32-ad14-95939a2c53d4:176256</guid><dc:creator>aaronjensen</dc:creator><slash:comments>4</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://scrum.codebetter.com/blogs/aaron.jensen/rsscomments.aspx?PostID=176256</wfw:commentRss><comments>http://scrum.codebetter.com/blogs/aaron.jensen/archive/2008/04/02/the-past-present-and-future-of-mocking.aspx#comments</comments><description>&lt;p&gt;&lt;em&gt;(Note: I&amp;#39;m going to speak about .NET mock projects here for the most part, but most of them have Java quasi-equivalents.) &lt;/em&gt;&lt;/p&gt;  &lt;p&gt;The original mocking frameworks like &lt;a href="http://nmock.org/"&gt;NMock&lt;/a&gt; required you to setup expectations by passing strings for method names. This was fragile and made refactoring more difficult. &lt;/p&gt;  &lt;p&gt;A few mock frameworks now allow you to define expectations and mock results in a strongly typed manner. &lt;a href="http://www.ayende.com/projects/rhino-mocks.aspx"&gt;Rhino Mocks&lt;/a&gt; and &lt;a href="http://www.typemock.com/"&gt;TypeMock&lt;/a&gt; use a record/replay method to setup expectations. The record replay method is mostly necessary because the same calls are made on the same objects under two different scenarios. This leads to a few issues. &lt;/p&gt;  &lt;p&gt;The first issue is confusion and barrier to entry. Many people have complained that the Record/Replay method is not straight forward and the whole paradigm is confusing. There are also complains about the naming, are you really recording and then replaying? It&amp;#39;s just kind of a strange thing. Of course most of us learn to live with it, understand it, and accept it for what it is. Recently though, a few mock frameworks have popped up that do away with this model.&lt;/p&gt;  &lt;p&gt;In the .NET world we have &lt;a href="http://code.google.com/p/moq/"&gt;Moq&lt;/a&gt;. Moq gets rid of the need for record/replay because recordings have a very different syntax. They use lambdas instead of actual calls to the mock object. This allows the framework to know when you are recording an expectation and when you are fulfilling an expectation. It adds a bit of noise in the form of &amp;quot;() =&amp;gt;&amp;quot; but all in all it&amp;#39;s not bad. Of course this requires C# 3.0, but it&amp;#39;s good to keep looking ahead. &lt;/p&gt;  &lt;p&gt;In the Java world we have &lt;a href="http://code.google.com/p/mockito/"&gt;Mockito&lt;/a&gt;. Mockito also does away with the record/replay model but it does it in a different way. At first I wasn&amp;#39;t a fan, but thinking about it more, I like it. Mockito has two main apis, stub and verify. Stub is equivalent to SetupResult.For, and verify is equivalent to Expect.Call with a verify. The interesting bit is that the stubbing happens before the the class under test is invoked and the verifying (which includes describing the method to be verified) happens after the class under test is invoked. This is best shown with an example stolen from the Mockito site:&lt;/p&gt;  &lt;pre class="java" name="code"&gt;  
  //stubbing using built-in anyInt() argument matcher
  stub(mockedList.get(anyInt())).toReturn(&amp;quot;element&amp;quot;);
  
  //stubbing using hamcrest (let&amp;#39;s say isValid() returns your own hamcrest matcher):
  stub(mockedList.contains(argThat(isValid()))).toReturn(&amp;quot;element&amp;quot;);
  
  //following prints &amp;quot;element&amp;quot;
  System.out.println(mockedList.get(999));
  
  //you can also verify using argument matcher
  verify(mockedList).get(anyInt());&lt;/pre&gt;

&lt;p&gt;Obviously it would take a bit of imagination to arrive at a .NET equivalent, but you get the idea. I like this because the normal test structure is Setup Stuff-&amp;gt;Do Stuff to Test-&amp;gt;Verify Stuff did what it should have. The normal record/replay model requires you to set up verifications before you actually Do Stuff (though you call VerifyAll afterwards). This is a bit less natural. I feel syntax like this (yeah, I like the new NUnit syntax) would be more intention revealing:&lt;/p&gt;

&lt;pre class="c-sharp" name="code"&gt;Assert.That(() =&amp;gt; someMock.Foo(), Was.Called);&lt;/pre&gt;

&lt;p&gt;Or:&lt;/p&gt;

&lt;pre class="c-sharp" name="code"&gt;Verify.That(() =&amp;gt; someMock.Foo()).WasCalled();&lt;/pre&gt;

&lt;p&gt;Then you would stub like this:&lt;/p&gt;

&lt;pre class="c-sharp" name="code"&gt;Stub.That(() =&amp;gt; someMock.Bar()).Returns(3);&lt;/pre&gt;

&lt;p&gt;&lt;em&gt;(Note: No idea if this is feasible or makes sense or not, my lambda experience is limited to light reading, but you get the idea. I&amp;#39;m sure the syntax could also be prettier.)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Rhino.Mocks is my current mock framework of choice. I&amp;#39;m used to it, I&amp;#39;ve lightly contributed to it, and I&amp;#39;ve been working with it for a while now. Despite that, I do think that there is definitely more to explore in the mocking arena especially with C# 3.0.&lt;/p&gt;

&lt;p&gt;There are lots of other fun things to talk about too... like &lt;a href="http://www.typemock.com/"&gt;TypeMock&lt;/a&gt;&amp;#39;s magic, but that&amp;#39;s another day still...&lt;/p&gt;&lt;img src="http://scrum.codebetter.com/aggbug.aspx?PostID=176256" width="1" height="1"&gt;</description><category domain="http://scrum.codebetter.com/blogs/aaron.jensen/archive/tags/frameworks/default.aspx">frameworks</category><category domain="http://scrum.codebetter.com/blogs/aaron.jensen/archive/tags/mocking/default.aspx">mocking</category></item><item><title>Moq's MockBehavior</title><link>http://scrum.codebetter.com/blogs/aaron.jensen/archive/2008/03/26/moq-s-mockbehavior.aspx</link><pubDate>Wed, 26 Mar 2008 16:29:14 GMT</pubDate><guid isPermaLink="false">d21fbbc9-c112-4f32-ad14-95939a2c53d4:175905</guid><dc:creator>aaronjensen</dc:creator><slash:comments>8</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://scrum.codebetter.com/blogs/aaron.jensen/rsscomments.aspx?PostID=175905</wfw:commentRss><comments>http://scrum.codebetter.com/blogs/aaron.jensen/archive/2008/03/26/moq-s-mockbehavior.aspx#comments</comments><description>&lt;p&gt;&lt;a href="http://www.clariusconsulting.net/blogs/kzu/archive/2007/12/18/LinqtoMockMoqisborn.aspx"&gt;Moq&lt;/a&gt; has been getting some press lately because it&amp;#39;s the newest mock framework on the block. I think it&amp;#39;s certainly interesting and I&amp;#39;ll have more to say on it later, but I wanted to briefly complain about one aspect real quick.&lt;/p&gt;  &lt;p&gt;Moq touts that it has a more simplified API when compared to something like &lt;a href="http://www.ayende.com/projects/rhino-mocks.aspx"&gt;Rhino.Mocks&lt;/a&gt;. The API has a single entry point which certainly aids discoverability, but I question one of the design decisions. I remember seeing someone say that Rhino had too many types of mocks and that that was confusing. Well, I don&amp;#39;t think it has this many different Mock Behaviors:&lt;/p&gt;  &lt;pre name="code" class="c-sharp"&gt;
  public enum MockBehavior
  {
    Strict, 
    Normal,
    Relaxed,
    Loose,
    Default = Normal,
  }&lt;/pre&gt;

&lt;p&gt;Why have this many? Does anyone know what they do just by looking at them? At least they&amp;#39;re documented, but the docs are quite a mouthful:&lt;/p&gt;

&lt;pre name="code" class="c-sharp"&gt;  public enum MockBehavior
  {
    /// 
    /// Causes the mock to always throw 
    /// an exception for invocations that don&amp;#39;t have a 
    /// corresponding expectation.
    /// 
    Strict, 
    /// 
    /// Matches the behavior of classes and interfaces 
    /// in equivalent manual mocks: abstract methods 
    /// need to have an expectation (override), as well 
    /// as all interface members. Other members (virtual 
    /// and non-virtual) can be called freely and will end up 
    /// invoking the implementation on the target type if available.
    /// 
    Normal,
    /// 
    /// Will only throw exceptions for abstract methods and 
    /// interface members which need to return a value and 
    /// don&amp;#39;t have a corresponding expectation.
    /// 
    Relaxed,
    /// 
    /// Will never throw exceptions, returning default  
    /// values when necessary (null for reference types 
    /// or zero for value types).
    /// 
    Loose,
    /// 
    /// Default mock behavior, which equals .
    /// 
    Default = Normal,
  }&lt;/pre&gt;

&lt;p&gt;I&amp;#39;m of the opinion that you should only have one type of Mock, and that&amp;#39;s what Rhino calls Dynamic and Moq calls Loose. I described why &lt;a href="http://blog.eleutian.com/2007/02/27/LooselycoupledMocks.aspx"&gt;here&lt;/a&gt;. If I wanted to simplify mocking, I&amp;#39;d start here.&lt;/p&gt;&lt;img src="http://scrum.codebetter.com/aggbug.aspx?PostID=175905" width="1" height="1"&gt;</description></item><item><title>The Eleutian Guys join the CodeBetter Guys</title><link>http://scrum.codebetter.com/blogs/aaron.jensen/archive/2008/03/19/the-eleutian-guys-join-the-codebetter-guys.aspx</link><pubDate>Wed, 19 Mar 2008 16:42:00 GMT</pubDate><guid isPermaLink="false">d21fbbc9-c112-4f32-ad14-95939a2c53d4:175605</guid><dc:creator>aaronjensen</dc:creator><slash:comments>3</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://scrum.codebetter.com/blogs/aaron.jensen/rsscomments.aspx?PostID=175605</wfw:commentRss><comments>http://scrum.codebetter.com/blogs/aaron.jensen/archive/2008/03/19/the-eleutian-guys-join-the-codebetter-guys.aspx#comments</comments><description>&lt;p&gt;As &lt;a href="http://codebetter.com/blogs/david_laribee/archive/2008/03/19/welcome-to-codebetter-aaron-and-jacob.aspx"&gt;Dave&lt;/a&gt; so promptly pointed out immediately after our grueling hazing that I still have not yet recovered from, &lt;a href="http://codebetter.com/blogs/jacob.lewallen/default.aspx"&gt;Jacob&lt;/a&gt; and I have been invited to join CodeBetter. I&amp;#39;m very excited to do so, thanks to everyone at CodeBetter! &lt;/p&gt;  &lt;p&gt;I&amp;#39;m going to cross-post to both our &lt;a href="http://blog.eleutian.com/"&gt;Eleutian Blog&lt;/a&gt; and my &lt;a href="http://codebetter.com/blogs/aaron.jensen/default.aspx"&gt;CodeBetter Blog&lt;/a&gt; for now, so don&amp;#39;t worry about adjusting your subscriptions unless you start seeing double... and don&amp;#39;t want to read my posts twice.&lt;/p&gt;  &lt;p&gt;Thanks again to CodeBetter for having us!&lt;/p&gt;&lt;img src="http://scrum.codebetter.com/aggbug.aspx?PostID=175605" width="1" height="1"&gt;</description><category domain="http://scrum.codebetter.com/blogs/aaron.jensen/archive/tags/random/default.aspx">random</category></item></channel></rss>