<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Dr. Random - Review</title>
    <link>http://www.drrandom.org/</link>
    <description>Random Thoughts for Random People</description>
    <language>en-us</language>
    <copyright>Casey Kramer</copyright>
    <lastBuildDate>Wed, 02 Sep 2009 17:36:02 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.3.9074.18820</generator>
    <managingEditor>casey.kramer@gmail.com</managingEditor>
    <webMaster>casey.kramer@gmail.com</webMaster>
    <item>
      <trackback:ping>http://www.drrandom.org/Trackback.aspx?guid=6d8cd4bb-5b28-4950-9eae-404355cad058</trackback:ping>
      <pingback:server>http://www.drrandom.org/pingback.aspx</pingback:server>
      <pingback:target>http://www.drrandom.org/PermaLink,guid,6d8cd4bb-5b28-4950-9eae-404355cad058.aspx</pingback:target>
      <dc:creator>Casey Kramer</dc:creator>
      <wfw:comment>http://www.drrandom.org/CommentView,guid,6d8cd4bb-5b28-4950-9eae-404355cad058.aspx</wfw:comment>
      <wfw:commentRss>http://www.drrandom.org/SyndicationService.asmx/GetEntryCommentsRss?guid=6d8cd4bb-5b28-4950-9eae-404355cad058</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I was pleased to find recently that Roy Osherove’s Art of Unit Testing was available
on Safari.  I have been following Roy’s blog for a while now, and was quite excited
at the prospect of him writing a book on Unit Testing.  It was only my personal
cheapness that kept me from shelling out the $25 to get the E-Book version from Manning
ahead of time.  I have to say, now that I have read it, that it would have been
well worth the money.  Before I get too deep I want to provide some context for
what I am about to say.
</p>
        <p>
          <strong>I consider myself an experienced TDD practitioner and Unit Test Writer<br /></strong>So that means that I was reading this book hoping to gain some insight. 
I wanted to find out how to write better, more readable, more maintainable tests. 
I was also hoping for a little bit of “atta-boy” affirmation that the way I do things
is the “right” way.  The astute reader may be able to tell that in order for
my first hope to be true, the second may have to get some points taken away. 
This was in fact the case, and to be honest, coming out of it I feel like I’ve gotten
more value from the things I’ve learned than I received from whatever ego stroking
may have occurred with what I am currently doing right.
</p>
        <p>
          <strong>So lets get started….<br /></strong>I was expecting the book to start out essentially as it did, some brief history
about the author and an introduction to Unit Testing for those who may not be familiar
with it.  I have to say I was expecting the book to be a little more TDD-centric
than it was, but I think most of that was my own bias for TDD as “The Only Way To
Write Software”.  Roy actually explained what TDD was, and also why he wasn’t
going to harp too much on it throughout the book.  I have to say, I can see why
he made the decision that he did.  I can also say that it seemed perfectly clear
to me that TDD is a technique that he feels has a lot a value, which made me happy. 
Since this is supposed to be a review from the perspective of an experienced practitioner
of TDD and Unit Testing, I’m not going to go into anything that was touched on in
the early chapters, apart from noting that they contained a general introduction to
the tools, technique and philosophy of unit testing.  I can also say that, though
I was already familiar with the material, I didn’t mind reading through it at all. 
Overall, Roy’s writing style was light and quite pleasant, even for a technical book.
</p>
        <p>
        </p>
        <p>
          <strong>And now into the meat of the book…<br /></strong>For me, things started getting interesting in Part 3 of the book.  This
is where issues of test design and organization are addressed.  This is one of
those areas that I feel like I need some guidance on, mostly because I developed my
testing idioms mostly through habit, and trial and error.  I look back on tests
I have written in the past (which could be as little as two days ago) and I wonder
how I could have come up with such a brittle, unmaintainable nightmare.  I feel
like I need guidance from the experts on what I can do better when writing my tests. 
Roy delivered on these items in chapter 7 “The pillars of good tests”.  One of
the lessons I took away from this was the value in testing one concept per test. 
I had heard this as “one assert per test” in the past, and scoffed at the idea. 
But Roy presents a very compelling argument for why this is a good idea, if you are
testing multiple concepts, you don’t know the extent of the problem when your test
fails.  And lets face it, the failing test is the reason we’re doing this whole
thing.  I’ve seen personally the failing test that just keeps failing. 
You tackle the issue from one failed assert only to rebuild, and find one right after
it which fails as well.  One of the issues I’ve had with this is the redundant
setup and configuration that could be required for exercising this concept, but this
issue is also addressed by the straight forward recommendation of creating clear and
understandable configuration methods.  In the past I have generally not been
really good about applying DRY to my test setup, which, I know, is another case of
treating tests differently from regular code.  Having someone in a position of
authority (like Roy) say, “put your setup in separate methods so you can re-use them
and make your tests more readable” made it okay to do the thing that I knew I should
be doing anyway.  The key concepts covered are making tests readable, maintainable,
and an accurate portrayal of the authors intent.
</p>
        <p>
          <strong>Even more in depth….<br /></strong>Section 4 goes even further and talks about how to integrate unit testing
into an organization which is not already doing it.  This is an interesting subject
to me as I have recently moved to a company which has not been doing unit testing
and TDD as part of their regular development process.  Roy draws on his experiences
as a consultant to provide some really good advice for how to go about enacting this
sort of change in an organization.  I particularly pleased with his candor when
he describes his failed attempts at integrating unit testing.  It would have
been quite easy to simply say “Based on my considerable expertise, these are the things
you need to do”, but he chooses instead to share some real-world experience in a straight
forward way that only adds to my respect for him as a professional.  In addition
to this, he touches on techniques for integrating testing into “legacy” code (i.e.
code which is not tested).  He does a good job at introducing some techniques
for testing what is essentially untestable code, which a very large nod at Michael
Feathers’ “Working Effectively with Legacy Code”. 
</p>
        <p>
The book ends with three appendices, one discussing the importance of testability
in the design process, one listing vairous testing tools (both Java and .Net), and
the last listing guidelines for conducting test reviews.  This last one is nice,
because it presents a concise view of all of the guidelines presented throughout the
book, and provides page references where you can get the “why” behind each.  
</p>
        <p>
          <strong>All in all…<br /></strong>This is a really good book, which should be part of any agile development
library.  It doesn’t matter if you are writing your first unit tests, or you’re
a seasoned pro, there is going to be something here for you.  I think it is great
that Roy has chosen to share his experience with the developer community in this way. 
I came into this book with some rather high expectations and I think they were met.
</p>
        <p>
          <strong>A note on TypeMock….<br /></strong>I remember seeing some criticism floating around on twitter suggesting the
book was rather pro TypeMock.  There was also the comment that Roy’s affiliation
with TypeMock was not made clear early on.  I can’t say I saw either of these
things when I was reading it.  For starters, I already knew Roy worked for TypeMock,
so perhaps that skewed my ability to objectively judge if the disclosure was done
in a timely manner or not.  I can say that the places in the book which there
seemed to be a preference for TypeMock were places where he stated things like “I
feel TypeMock has a better syntax in this case”, or “TypeMock is the only tool with
provides these capabilities”.  For starters, the first is a statement of preference. 
Sure Roy helped design the API for TypeMock, so it seems only natural that he would
prefer it to other frameworks, but having used it I would have to agree with the statement. 
It is a great API, and example if a fluent interface done well.  The second comment
is also plain fact.  Of the mocking libraries available in the .Net space, TypeMock
is the only one that allows you to swap instances of objects in place, without making
changes to the classes using them.  You can argue over whether or not this is
a good or a bad thing, but the fact remains that it is a feature specific to TypeMock. 
Maybe I was expecting something more blatant and obvious, but I just didn’t see it.
</p>
        <img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=6d8cd4bb-5b28-4950-9eae-404355cad058" />
      </body>
      <title>Review: Art of Unit Testing by Roy Osherove</title>
      <guid isPermaLink="false">http://www.drrandom.org/PermaLink,guid,6d8cd4bb-5b28-4950-9eae-404355cad058.aspx</guid>
      <link>http://www.drrandom.org/2009/09/02/ReviewArtOfUnitTestingByRoyOsherove.aspx</link>
      <pubDate>Wed, 02 Sep 2009 17:36:02 GMT</pubDate>
      <description>&lt;p&gt;
I was pleased to find recently that Roy Osherove’s Art of Unit Testing was available
on Safari.&amp;nbsp; I have been following Roy’s blog for a while now, and was quite excited
at the prospect of him writing a book on Unit Testing.&amp;nbsp; It was only my personal
cheapness that kept me from shelling out the $25 to get the E-Book version from Manning
ahead of time.&amp;nbsp; I have to say, now that I have read it, that it would have been
well worth the money.&amp;nbsp; Before I get too deep I want to provide some context for
what I am about to say.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;I consider myself an experienced TDD practitioner and Unit Test Writer&lt;br&gt;
&lt;/strong&gt;So that means that I was reading this book hoping to gain some insight.&amp;nbsp;
I wanted to find out how to write better, more readable, more maintainable tests.&amp;nbsp;
I was also hoping for a little bit of “atta-boy” affirmation that the way I do things
is the “right” way.&amp;nbsp; The astute reader may be able to tell that in order for
my first hope to be true, the second may have to get some points taken away.&amp;nbsp;
This was in fact the case, and to be honest, coming out of it I feel like I’ve gotten
more value from the things I’ve learned than I received from whatever ego stroking
may have occurred with what I am currently doing right.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;So lets get started….&lt;br&gt;
&lt;/strong&gt;I was expecting the book to start out essentially as it did, some brief history
about the author and an introduction to Unit Testing for those who may not be familiar
with it.&amp;nbsp; I have to say I was expecting the book to be a little more TDD-centric
than it was, but I think most of that was my own bias for TDD as “The Only Way To
Write Software”.&amp;nbsp; Roy actually explained what TDD was, and also why he wasn’t
going to harp too much on it throughout the book.&amp;nbsp; I have to say, I can see why
he made the decision that he did.&amp;nbsp; I can also say that it seemed perfectly clear
to me that TDD is a technique that he feels has a lot a value, which made me happy.&amp;nbsp;
Since this is supposed to be a review from the perspective of an experienced practitioner
of TDD and Unit Testing, I’m not going to go into anything that was touched on in
the early chapters, apart from noting that they contained a general introduction to
the tools, technique and philosophy of unit testing.&amp;nbsp; I can also say that, though
I was already familiar with the material, I didn’t mind reading through it at all.&amp;nbsp;
Overall, Roy’s writing style was light and quite pleasant, even for a technical book.
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;And now into the meat of the book…&lt;br&gt;
&lt;/strong&gt;For me, things started getting interesting in Part 3 of the book.&amp;nbsp; This
is where issues of test design and organization are addressed.&amp;nbsp; This is one of
those areas that I feel like I need some guidance on, mostly because I developed my
testing idioms mostly through habit, and trial and error.&amp;nbsp; I look back on tests
I have written in the past (which could be as little as two days ago) and I wonder
how I could have come up with such a brittle, unmaintainable nightmare.&amp;nbsp; I feel
like I need guidance from the experts on what I can do better when writing my tests.&amp;nbsp;
Roy delivered on these items in chapter 7 “The pillars of good tests”.&amp;nbsp; One of
the lessons I took away from this was the value in testing one concept per test.&amp;nbsp;
I had heard this as “one assert per test” in the past, and scoffed at the idea.&amp;nbsp;
But Roy presents a very compelling argument for why this is a good idea, if you are
testing multiple concepts, you don’t know the extent of the problem when your test
fails.&amp;nbsp; And lets face it, the failing test is the reason we’re doing this whole
thing.&amp;nbsp; I’ve seen personally the failing test that just keeps failing.&amp;nbsp;
You tackle the issue from one failed assert only to rebuild, and find one right after
it which fails as well.&amp;nbsp; One of the issues I’ve had with this is the redundant
setup and configuration that could be required for exercising this concept, but this
issue is also addressed by the straight forward recommendation of creating clear and
understandable configuration methods.&amp;nbsp; In the past I have generally not been
really good about applying DRY to my test setup, which, I know, is another case of
treating tests differently from regular code.&amp;nbsp; Having someone in a position of
authority (like Roy) say, “put your setup in separate methods so you can re-use them
and make your tests more readable” made it okay to do the thing that I knew I should
be doing anyway.&amp;nbsp; The key concepts covered are making tests readable, maintainable,
and an accurate portrayal of the authors intent.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Even more in depth….&lt;br&gt;
&lt;/strong&gt;Section 4 goes even further and talks about how to integrate unit testing
into an organization which is not already doing it.&amp;nbsp; This is an interesting subject
to me as I have recently moved to a company which has not been doing unit testing
and TDD as part of their regular development process.&amp;nbsp; Roy draws on his experiences
as a consultant to provide some really good advice for how to go about enacting this
sort of change in an organization.&amp;nbsp; I particularly pleased with his candor when
he describes his failed attempts at integrating unit testing.&amp;nbsp; It would have
been quite easy to simply say “Based on my considerable expertise, these are the things
you need to do”, but he chooses instead to share some real-world experience in a straight
forward way that only adds to my respect for him as a professional.&amp;nbsp; In addition
to this, he touches on techniques for integrating testing into “legacy” code (i.e.
code which is not tested).&amp;nbsp; He does a good job at introducing some techniques
for testing what is essentially untestable code, which a very large nod at Michael
Feathers’ “Working Effectively with Legacy Code”. 
&lt;/p&gt;
&lt;p&gt;
The book ends with three appendices, one discussing the importance of testability
in the design process, one listing vairous testing tools (both Java and .Net), and
the last listing guidelines for conducting test reviews.&amp;nbsp; This last one is nice,
because it presents a concise view of all of the guidelines presented throughout the
book, and provides page references where you can get the “why” behind each.&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;All in all…&lt;br&gt;
&lt;/strong&gt;This is a really good book, which should be part of any agile development
library.&amp;nbsp; It doesn’t matter if you are writing your first unit tests, or you’re
a seasoned pro, there is going to be something here for you.&amp;nbsp; I think it is great
that Roy has chosen to share his experience with the developer community in this way.&amp;nbsp;
I came into this book with some rather high expectations and I think they were met.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;A note on TypeMock….&lt;br&gt;
&lt;/strong&gt;I remember seeing some criticism floating around on twitter suggesting the
book was rather pro TypeMock.&amp;nbsp; There was also the comment that Roy’s affiliation
with TypeMock was not made clear early on.&amp;nbsp; I can’t say I saw either of these
things when I was reading it.&amp;nbsp; For starters, I already knew Roy worked for TypeMock,
so perhaps that skewed my ability to objectively judge if the disclosure was done
in a timely manner or not.&amp;nbsp; I can say that the places in the book which there
seemed to be a preference for TypeMock were places where he stated things like “I
feel TypeMock has a better syntax in this case”, or “TypeMock is the only tool with
provides these capabilities”.&amp;nbsp; For starters, the first is a statement of preference.&amp;nbsp;
Sure Roy helped design the API for TypeMock, so it seems only natural that he would
prefer it to other frameworks, but having used it I would have to agree with the statement.&amp;nbsp;
It is a great API, and example if a fluent interface done well.&amp;nbsp; The second comment
is also plain fact.&amp;nbsp; Of the mocking libraries available in the .Net space, TypeMock
is the only one that allows you to swap instances of objects in place, without making
changes to the classes using them.&amp;nbsp; You can argue over whether or not this is
a good or a bad thing, but the fact remains that it is a feature specific to TypeMock.&amp;nbsp;
Maybe I was expecting something more blatant and obvious, but I just didn’t see it.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=6d8cd4bb-5b28-4950-9eae-404355cad058" /&gt;</description>
      <comments>http://www.drrandom.org/CommentView,guid,6d8cd4bb-5b28-4950-9eae-404355cad058.aspx</comments>
      <category>.Net</category>
      <category>TDD</category>
      <category>Review</category>
    </item>
    <item>
      <trackback:ping>http://www.drrandom.org/Trackback.aspx?guid=24aaf20e-9858-42a8-abc0-75f6b7f128b4</trackback:ping>
      <pingback:server>http://www.drrandom.org/pingback.aspx</pingback:server>
      <pingback:target>http://www.drrandom.org/PermaLink,guid,24aaf20e-9858-42a8-abc0-75f6b7f128b4.aspx</pingback:target>
      <dc:creator>Casey Kramer</dc:creator>
      <wfw:comment>http://www.drrandom.org/CommentView,guid,24aaf20e-9858-42a8-abc0-75f6b7f128b4.aspx</wfw:comment>
      <wfw:commentRss>http://www.drrandom.org/SyndicationService.asmx/GetEntryCommentsRss?guid=24aaf20e-9858-42a8-abc0-75f6b7f128b4</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
The folks at <a href="http://www.typemock.com/">TypeMock</a> have released a new UnitTesting
tool aimed specifically at catching deadlocks in multithreaded code called <a href="http://www.typemock.com/learn_about_typemock_racer.php">TypeMock
Racer</a>, and what's more they are <a href="http://blog.typemock.com/2009/06/easy-deadlock-detection-get-free.html" target="_blank">offering
free licenses to folks willing to review it during the 21 day free trial period</a>. 
As anyone who knows me can testify to, I am a whore for free-bees, so I decided to
take them up on this.
</p>
        <p>
          <strong>For the impatient, here is the executive summary:<br /></strong>This is a good tool.  Period.  It is, however, also a very specific
tool that is intended to help find very specific problems.  If you are not doing
any multithreaded code, there is no need to have it in your toolbox.  The cost
($890 US) is high enough that it doesn't really seem worth it to get it "just in case"
(unless, of course, you right a nice review on your blog and get a free license). 
If you <strong><em>do</em></strong> work with multithreaded code, and you<strong><em> are</em></strong> concerned
about deadlocks, this tool will save you lots of time, which ultimately means money.
</p>
        <p>
          <strong>Now, for the details</strong>
        </p>
        <p>
First of all, this is a tool from TypeMock, so I expected some pretty incredible things,
even at the 1.0 release.  After all, their flagship product <a href="http://www.typemock.com/learn_about_typemock_isolator.php">TypeMock
Isolator</a> is phenomenally powerful, so much so that the free license I was given
for <a href="http://www.drrandom.org/PermaLink,guid,5200ee4d-d92b-4931-9005-705f523228b1.aspx" target="_blank">posting
an advertisement</a> for the release of their ASP.Net product has gone largely unused. 
I'm just scared of it.  It's like having access to a 50 horse-power tablesaw
with no blade guard.  I may be careful enough to use it correctly most of the
time, but the fact that it can take off my forearm without pausing to ask my permission
makes me reluctant to get too close.  I do know that there are some very real
problems that the tool can solve that just can't be done with any other tool, so I
have every intent of getting up my courage, grabbing a first aid kit, and jumping
in to see what I can do...eventually.
</p>
        <p>
But Racer is different.  It is a very powerful tool with a very specific purpose. 
It makes it easier to run tests in multiple threads, and detect deadlocks.  As
far as I can tell, it just detects deadlocks, not race conditions, as it's name seems
to suggest.  Not that this is bad, just that it only covers half of the rather
shaky ground that is traveled while working with multithreaded code.  It is arguable,
however, that dealing with deadlocks is the more difficult of the two problems, so
getting this one tacked first is not a bad thing.
</p>
        <p>
          <strong>So how does it work?</strong>
        </p>
        <p>
Fairly straight forward really.  Start with a regular unit test, that is exercising
some code that is utilizing locks in an attempt to be thread safe.  It looks
like Racer supports just about every form of Synchronization supported by .Net, so
you can feel free to use whichever mechanism you are more comfortable with to get
the work done.  Now that you have a test, the simplest way to make use of Racer,
is to add the Typemock.Racer library reference to your test project, and then add
a ParrellelInspection attribute to the test.  This causes Racer to do it's thing,
which by default means running the test once with a single thread, and then run it
again using multiple threads (2 by default).  If there are no problems, nothing
much new happens.  You see some additional information about the test being run
first with one thread, and then multiple, and something about scenarios executed...nothing
that exciting.  The coolness happens when you actually get a deadlock. 
For starters you test output includes a bunch of new information, the most noticeable
of which is a big "DEADLOCK discovered when running the following" message. 
Also is a description of the scenario that caused the deadlock.  Something like
"Thread 1 acquired lock A, Thread 1 released lock A, Thread 2 attempted to acquire
lock B, etc".  Cooler yet is a message that says "To reproduce or debug this,
copy the following attribute, paste it on top of your test and rerun the test:", followed
by something that looks like 
<br /></p>
        <pre class="brush: csharp" name="code">[SpecificScenario("2", 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 2)]</pre>
        <p>
          <br />
Which, while being completely incomprehensible to humans, causes your test to run
in the specific configuration which caused the deadlock to occur.  This means
that you can accurately recreate the exact situation that lead to the problem. 
If you have ever had to try to track down a deadlock in a live system, you will realize
that this information just saved you countless hours of trying to recreate the production
environment, and lots of trial and error getting things into the state that caused
the problem.  One word: Brilliant!
</p>
        <p>
          <strong>So what is the down side?</strong>
        </p>
        <p>
I have to say that I've not yet been able to figure out how Racer determines what
scenarios to run, or what the bits in the "SpecificScenario" attribute mean(well,
the first string parameter is the number of threads, and the other numbers refer to
the specific threads, and match the summary of the scenario, but beyond that, not
a clue).  It would be interesting to know these things, but not really critical,
as long as you are confident all appropriate scenarios are being executed.
</p>
        <p>
There is also an interesting feature that I can't quite get my head around. 
When you run a test with a deadlock, an image is generated, which is supposed to be
a visual representation of the scenario that created the deadlock.  Here is an
example:
</p>
        <p>
          <img src="content/binary/tmp442.tmp.png" border="0" />
          <br />
 
</p>
        <p>
Now, I see the three objects I was locking against (sync1, sync2, and sync3), and
I guess the odd rhombus shaped objects represent the threads, but I'm not really sure
what the diagram is trying to tell me.  This is, no doubt, something which is
still fairly raw in this early version.  I think it could be very useful if it
were clearer what the shapes and arrows represent, but at this point it is simply
a cleaver bit of kit that you can show somebody so that they can be confused too.
</p>
        <p>
The last issue I can see with it currently is the price.  At $890 US for a single
user license, it isn't an impulse buy.  Granted, I think it can pay for itself
easily after finding a few deadlocks in some production code (the earlier they are
found the more that find is worth), but I don't see it being a terribly easy sell
for management, at least if you are not actively trying to correct a threading issue. 
I feel pretty fortunate that I work for a company that understands the value of good
tools, and is willing to provide them if there is a need, but I think it would take
some convincing to get management to agree to purchase Racer simply because it is
a good tool, and could really pay off "one day".  If we were facing a threading
issue, and I could demonstrate that racer would allow us to find it, and accurately
reproduce it, it would be a fairly easy sell.  
</p>
        <p>
          <strong>So overall</strong>
        </p>
        <p>
I think this is an excellent tool.  Based on the fact that this is an early release,
I can only see it getting better over time.  It is a rather pricey tool, however,
so you may have to do some convincing to get the boss-man to get you a license. 
There is a 21-day trial, however, so if you find yourself in a situation where you
either have, or you could conceivably have, a risk of deadlock, then grab the trial,
and use the first detected deadlock as justification to get a full license.  
</p>
        <img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=24aaf20e-9858-42a8-abc0-75f6b7f128b4" />
      </body>
      <title>Review - TypeMock Racer and Unit Testing Multithreaded Applications</title>
      <guid isPermaLink="false">http://www.drrandom.org/PermaLink,guid,24aaf20e-9858-42a8-abc0-75f6b7f128b4.aspx</guid>
      <link>http://www.drrandom.org/2009/06/19/ReviewTypeMockRacerAndUnitTestingMultithreadedApplications.aspx</link>
      <pubDate>Fri, 19 Jun 2009 16:31:17 GMT</pubDate>
      <description>&lt;p&gt;
The folks at &lt;a href="http://www.typemock.com/"&gt;TypeMock&lt;/a&gt; have released a new UnitTesting
tool aimed specifically at catching deadlocks in multithreaded code called &lt;a href="http://www.typemock.com/learn_about_typemock_racer.php"&gt;TypeMock
Racer&lt;/a&gt;, and what's more they are &lt;a href="http://blog.typemock.com/2009/06/easy-deadlock-detection-get-free.html" target="_blank"&gt;offering
free licenses to folks willing to review it during the 21 day free trial period&lt;/a&gt;.&amp;nbsp;
As anyone who knows me can testify to, I am a whore for free-bees, so I decided to
take them up on this.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;For the impatient, here is the executive summary:&lt;br&gt;
&lt;/strong&gt;This is a good tool.&amp;nbsp; Period.&amp;nbsp; It is, however, also a very specific
tool that is intended to help find very specific problems.&amp;nbsp; If you are not doing
any multithreaded code, there is no need to have it in your toolbox.&amp;nbsp; The cost
($890 US) is high enough that it doesn't really seem worth it to get it "just in case"
(unless, of course, you right a nice review on your blog and get a free license).&amp;nbsp;
If you &lt;strong&gt;&lt;em&gt;do&lt;/em&gt;&lt;/strong&gt; work with multithreaded code, and you&lt;strong&gt;&lt;em&gt; are&lt;/em&gt;&lt;/strong&gt; concerned
about deadlocks, this tool will save you lots of time, which ultimately means money.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Now, for the details&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
First of all, this is a tool from TypeMock, so I expected some pretty incredible things,
even at the 1.0 release.&amp;nbsp; After all, their flagship product &lt;a href="http://www.typemock.com/learn_about_typemock_isolator.php"&gt;TypeMock
Isolator&lt;/a&gt; is phenomenally powerful, so much so that the free license I was given
for &lt;a href="http://www.drrandom.org/PermaLink,guid,5200ee4d-d92b-4931-9005-705f523228b1.aspx" target="_blank"&gt;posting
an advertisement&lt;/a&gt; for the release of their ASP.Net product has gone largely unused.&amp;nbsp;
I'm just scared of it.&amp;nbsp; It's like having access to a 50 horse-power tablesaw
with no blade guard.&amp;nbsp; I may be careful enough to use it correctly most of the
time, but the fact that it can take off my forearm without pausing to ask my permission
makes me reluctant to get too close.&amp;nbsp; I do know that there are some very real
problems that the tool can solve that just can't be done with any other tool, so I
have every intent of getting up my courage, grabbing a first aid kit, and jumping
in to see what I can do...eventually.
&lt;/p&gt;
&lt;p&gt;
But Racer is different.&amp;nbsp; It is a very powerful tool with a very specific purpose.&amp;nbsp;
It makes it easier to run tests in multiple threads, and detect deadlocks.&amp;nbsp; As
far as I can tell, it just detects deadlocks, not race conditions, as it's name seems
to suggest.&amp;nbsp; Not that this is bad, just that it only covers half of the rather
shaky ground that is traveled while working with multithreaded code.&amp;nbsp; It is arguable,
however, that dealing with deadlocks is the more difficult of the two problems, so
getting this one tacked first is not a bad thing.
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;So how does it work?&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Fairly straight forward really.&amp;nbsp; Start with a regular unit test, that is exercising
some code that is utilizing locks in an attempt to be thread safe.&amp;nbsp; It looks
like Racer supports just about every form of Synchronization supported by .Net, so
you can feel free to use whichever mechanism you are more comfortable with to get
the work done.&amp;nbsp; Now that you have a test, the simplest way to make use of Racer,
is to add the Typemock.Racer library reference to your test project, and then add
a ParrellelInspection attribute to the test.&amp;nbsp; This causes Racer to do it's thing,
which by default means running the test once with a single thread, and then run it
again using multiple threads (2 by default).&amp;nbsp; If there are no problems, nothing
much new happens.&amp;nbsp; You see some additional information about the test being run
first with one thread, and then multiple, and something about scenarios executed...nothing
that exciting.&amp;nbsp; The coolness happens when you actually get a deadlock.&amp;nbsp;
For starters you test output includes a bunch of new information, the most noticeable
of which is a big "DEADLOCK discovered when running the following" message.&amp;nbsp;
Also is a description of the scenario that caused the deadlock.&amp;nbsp; Something like
"Thread 1 acquired lock A, Thread 1 released lock A, Thread 2 attempted to acquire
lock B, etc".&amp;nbsp; Cooler yet is a message that says "To reproduce or debug this,
copy the following attribute, paste it on top of your test and rerun the test:", followed
by something that looks like 
&lt;br&gt;
&lt;/p&gt;
&lt;pre class="brush: csharp" name="code"&gt;[SpecificScenario("2", 1, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 2)]&lt;/pre&gt;
&lt;p&gt;
&lt;br&gt;
Which, while being completely incomprehensible to humans, causes your test to run
in the specific configuration which caused the deadlock to occur.&amp;nbsp; This means
that you can accurately recreate the exact situation that lead to the problem.&amp;nbsp;
If you have ever had to try to track down a deadlock in a live system, you will realize
that this information just saved you countless hours of trying to recreate the production
environment, and lots of trial and error getting things into the state that caused
the problem.&amp;nbsp; One word: Brilliant!
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;So what is the down side?&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
I have to say that I've not yet been able to figure out how Racer determines what
scenarios to run, or what the bits in the "SpecificScenario" attribute mean(well,
the first string parameter is the number of threads, and the other numbers refer to
the specific threads, and match the summary of the scenario, but beyond that, not
a clue).&amp;nbsp; It would be interesting to know these things, but not really critical,
as long as you are confident all appropriate scenarios are being executed.
&lt;/p&gt;
&lt;p&gt;
There is also an interesting feature that I can't quite get my head around.&amp;nbsp;
When you run a test with a deadlock, an image is generated, which is supposed to be
a visual representation of the scenario that created the deadlock.&amp;nbsp; Here is an
example:
&lt;/p&gt;
&lt;p&gt;
&lt;img src="content/binary/tmp442.tmp.png" border="0"&gt;
&lt;br&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Now, I see the three objects I was locking against (sync1, sync2, and sync3), and
I guess the odd rhombus shaped objects represent the threads, but I'm not really sure
what the diagram is trying to tell me.&amp;nbsp; This is, no doubt, something which is
still fairly raw in this early version.&amp;nbsp; I think it could be very useful if it
were clearer what the shapes and arrows represent, but at this point it is simply
a cleaver bit of kit that you can show somebody so that they can be confused too.
&lt;/p&gt;
&lt;p&gt;
The last issue I can see with it currently is the price.&amp;nbsp; At $890 US for a single
user license, it isn't an impulse buy.&amp;nbsp; Granted, I think it can pay for itself
easily after finding a few deadlocks in some production code (the earlier they are
found the more that find is worth), but I don't see it being a terribly easy sell
for management, at least if you are not actively trying to correct a threading issue.&amp;nbsp;
I feel pretty fortunate that I work for a company that understands the value of good
tools, and is willing to provide them if there is a need, but I think it would take
some convincing to get management to agree to purchase Racer simply because it is
a good tool, and could really pay off "one day".&amp;nbsp; If we were facing a threading
issue, and I could demonstrate that racer would allow us to find it, and accurately
reproduce it, it would be a fairly easy sell.&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;So overall&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
I think this is an excellent tool.&amp;nbsp; Based on the fact that this is an early release,
I can only see it getting better over time.&amp;nbsp; It is a rather pricey tool, however,
so you may have to do some convincing to get the boss-man to get you a license.&amp;nbsp;
There is a 21-day trial, however, so if you find yourself in a situation where you
either have, or you could conceivably have, a risk of deadlock, then grab the trial,
and use the first detected deadlock as justification to get a full license.&amp;nbsp; 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.drrandom.org/aggbug.ashx?id=24aaf20e-9858-42a8-abc0-75f6b7f128b4" /&gt;</description>
      <comments>http://www.drrandom.org/CommentView,guid,24aaf20e-9858-42a8-abc0-75f6b7f128b4.aspx</comments>
      <category>.Net</category>
      <category>Review</category>
      <category>TDD</category>
      <category>Tools</category>
    </item>
  </channel>
</rss>