Home
Releases
Discussions
Issue Tracker
Source Code
Stats
People
License
RSS RSS Feed
Search Wiki:
Summary Description
A framework that dynamically generates stub objects for your classes to support creating unit tests structured according to the 3A pattern (arrange/act/assert). Also supports refactoring (no string identifiers) and does not require interfaces.

Why a stub framework versus a mock framework?
Unit tests are a way of life for my development activities, but some things have always bugged me about mock object frameworks:
  • They do not support using the 3A pattern (Arrange/Act/Assert) because both the Expect and Record style syntax effectively means specifying your Assert criteria in your Arrange.
  • The Record or Expect syntax never seemed intuitive or easy to read to me.
  • Some mock frameworks require an interface to mock a class.
  • Some mock frameworks use string identifiers which prevent using refactoring tools.
I prefer using stubs over mocks, but got tired of hand creating my stub code so eventually got tired enough to roll up my sleeves and create a framework that suits me.

What does unit test code look like using the Attach Stub Framework?
Here is the examples page.

What is the difference between a stub and a mock?
Here is a link to Martin Fowler's paper "Mocks Aren't Stubs" which provides a detailed explanation of the difference (he prefers the stub approach as well).

What else?
That's it. Pretty straightforward. It works well for how I like to do unit testing, and so here it is for others who have similar preferences.
Last edited Jul 21 2007 at 1:11 AM  by jwanagel, version 11
Comments
justinc wrote  Mar 27 2007 at 9:47 PM  
Looks cool, what is Attach doing behind the scenes to detect if the given method is executed?

jwanagel wrote  Apr 3 2007 at 9:19 PM  
It dynamically generates a class that inherits from the class you specify, and overloads the methods to provide the interception capability. Check this file to see where it is generating the subclass: http://www.codeplex.com/attach/SourceControl/FileView.aspx?itemId=214134&changeSetId=14694

ocenteno wrote  Jul 4 2007 at 10:33 PM  
Hi, my development team is currently using NET 1.1.
I really like your preferences for unit testing. Are there any plans of releasing Attach for .NET 1.1?

jwanagel wrote  Jul 21 2007 at 7:02 AM  
I'm sorry, but I'm not really up for trying to make a .NET 1.1 version.

dcazzulino wrote  Apr 24 at 5:06 AM  
Hi Jonathan,
in most practical cases, stub behavior is intermixed with the need for true mock behavior (verification) even within the same interface. So typically it makes more sense to have a true mocking framework that has good stub support, rather than just stubs and then falling short when you need more...

I'd like to know your thoughts on MoQ with the new 3A-friendly feature explained at http://www.clariusconsulting.net/blogs/kzu/archive/2008/04/22/ImprovingMoQtoallowarrangeactasserttestingstyle.aspx

Thanks!

dcazzulino wrote  Apr 24 at 5:08 AM  
Also, note that with the next version of MoQ, none of your four reasons for going with this would apply:

* Will support 3A style
* Never had record/replay semantics
* Doesn't require an interface to mock a class
* Doesn't use string identifiers

Updating...