Test-Driven Development with Typemock Isolator
Isolator .NET simplifies your unit testing by providing a flexible and convenient way to eliminate dependencies between objects.
A key issue in unit testing is determining what code actually failed. The solution is to replace calls to the "real" objects with calls to replacement code that's so simple it can't fail.
Typemock Isolator dramatically reduces the time required to set up these mocked scenarios. Adding three lines of Isolator code to your test will intercept that call and send it to an arbitrary method of your choosing. In that arbitrary method you can have a DataSet (or, perhaps, a List of Entity Framework objects) containing fixed values returned to the method under test. Those fixed values allow you to run your test and be confident that, should the test fail, the problem is with the method and not with the Data Access Layer (DAL) that's been bypassed or the data currently in the database.
As an example, this Isolator code, running under Visual Studio Test, first creates a mock DAL object and specifies that the next time a DAL is created this mock DAL should be used. It also ties the DAL's GetCustomersByRegion method to the output from a mock method called FixedCustomerValues. The test code then calls CustomersInRegionWithFreightCharges, which, presumably, calls the DAL's GetCustomersByRegion but will now get the results of the mocked method:
DAL mockDAL = Isolate.Fake.Instance<dal>();
CustomerFactorycf = newCustomerFactory();
List<Customer> res = cf.CustomersInRegionWithFreightCharges("SP");
While this test follows the current Arrange, Act, Assert (or AAA) model for mocking, the Isolator API also supports the old Record/Replay and Reflective Mocks models.
[Click on image for larger view.]
|Typemock Isolator Trace.Isolator includes a Trace tool that leverages the Isolator profiler-based architecture to report on what Isolator has done for you.|
Isolator is a profiler-based tool that intercepts method calls (other mocking frameworks generate replacement classes). This means that Isolator doesn't really care how the "real" object is constructed, so Isolator can work with static/Shared methods, sealed classes, objects created with the New keyword rather than the Isolator framework and legacy code (regardless of its inheritance structure) -- you can even mock private members. There's some overhead associated with running a profiler like Isolator, but you can disable Typemock from a menu added to your Visual Studio menu bar.
The Isolator package includes some other goodies, including a command-line runner, the TeamMate add-in that works with several profilers to report code coverage, a Lint tool that flags common problems in tests, and the IntelliTest add-in that provides support for generating tests as you write your code (Lint and IntelliTest are not available for Visual Basic tests).
I liked Typemock very much: I found the API syntax easy to use (great Help system) and the additional tools to be genuinely useful. But it's worth noting there are many free tools in this area: the venerable Rhino Mocks, Moq and FakeItEasy, among others. I don't think any of these tools provide all of the features and functionality that Typemock offers, but they might meet your needs and pocketbook.
Price: $799 for developer edition; $2,499 for build server license
Quick Facts: A mocking framework for isolating code under test from its dependencies
Pros: Easy to use with an extensive API that handles a variety of typical testing scenarios; several additional tools
Cons: Not all features available in Visual Basic
Peter Vogel is a system architect and principal in PH&V Information Services. PH&V provides full-stack consulting from UX design through object modeling to database design. Peter tweets about his VSM columns with the hashtag #vogelarticles. His blog posts on user experience design can be found at http://blog.learningtree.com/tag/ui/.