December 2006 Entries

The fundamental problems and impracticality of using MSTest

 

I can't help but chime in about MSTest, in repsonse to the latest post by Ayende regarding the comments on one of Scott Bellware's posts.  This is just another area that Microsoft just doesn't seem to "get".  If you really understand the importance of the TDD rhythm, you know that speed is key.  That rapid feedback cycle is where, the high productivity paired with writing high quality code, happens.  If the time it takes you to write a test, make it fail and write the code to make it pass is more than a minute or two, you're not being as productive as you can be. 

TDD != Unit Test Generation

I've seen first hand (and am still seeing) how slow this process can be using MSTest and the "Test View" in Visual Studio 2005.  Sure it's got pretty colors but the important thing to remember is that Red-Green-Refactor is about a MINDSET, not COLORS!  Just because you've got reds and greens showing up in some window does NOT mean you're doing TDD.  Especially when Microsoft has made it so easy to generate unit tests for you.  As most of you know, this 'caused quite a backlash from those of us that are TDD practitioners in the real world.  Thank goodness Jeffrey Palermo set 'em straight.  :)

Miserably Slow Testing

But back to MSTest.  One of the primary reasons MSTest is so slow is that for every single test run, it creates copies of ALL of the assemblies into a unique testing folder under the "TestResults" folder.  It may not sound like a big deal, but I've seen this cause tests to run at least 3-4 times longer than with NUnit or TestDriven.NET (with MSTest).  But more on TestDriven.NET in a sec.  I understand that by creating copies of the assemblies for each test run, it better facilitates publishing those results into the Team Foundation Server data warehouse.  But at the very least, this should be optional.  It's highly impractical that you'll be publishing test results to the data warehouse while implementing a feature in a TDD session.  It would just break the whole TDD rhythm. 

Is There Hope For MSTest?

If you absolutely have to use MSTest, the tool that makes it bearable is TestDriven.NET.  I personally think that the TestDriven.NET plug-in has single handedly saved MSTest from imploding.  Just bind it to Ctrl-T (thanks to a tip from my co-worker, Paul) and you have a frictionless TDD experience.  It's hands down the fastest way to run tests (NUnit or MSTest) in Visual Studio 2005. 

Getting Into The Rhythm

What makes TestDriven.NET so great, is you can just simply write your test, Ctrl-T to see if fail very quickly, implement the code, Ctrl-T again and see it pass.  Usually all within a matter of seconds because it only runs the one test where your cursor is located.  One of the newest features (either it's new, or I've just recently discovered it) is that you don't even have to navigate back to your test method to re-run your last test.  Jamie's added an option for re-running your last test method no matter where your cursor is located.  This speeds things up even more because you can actually just stay in the code your implementing and repeatedly run the same test over and over.  This is very handy during the refactoring phase of TDD. 

Where MSTest (without TestDriven.NET) Misses The Mark

These simple features are what MSTest is missing.  You have to open up separate windows (i.e. Test View, Test Results, etc.) and highlight the test you want to run, etc.  It's just not the best way to do things.  As Scott noted, I have to wonder why Microsoft seemed to have developed this stuff in a vacuum, without consulting the folks who actually practice TDD.

So the bottom line is that if you want to be as productive as possible in your TDD adventures, use TestDriven.NET, preferrably with NUnit.  My TDD approach is kind of a hybrid between running tests using TestDriven.NET in Visual Studio 2005 and with my automated build script using nunit-console.exe. 

Perhaps I'll post a followup, if anyone's interested, detailing how I do TDD along with the tips and tools that I use to help me be productive as possible.

MediaPortal - MCE Killer?

 

I ran across this awesome open-source project called MediaPortal from a recent lifehacker article and it really caught my eye.  So I downloaded it and installed it as a test on one of my XP boxes, and Wow! 

We've been using XP Media Center for a couple years now in our living room and it's been ok for watching and recording TV.  We started out using the pictures, music and video features of it too, but found them somewhat lacking.  Especially the music features, since it's obviously optimized for use with WMA's (i.e album art, etc.).  (I prefer to keep everything in MP3 to remain as flexible as possible and I never could get MCE to pick up the album art embedded in my MP3s.)  So we haven't used any other features besides TV in a long time.  There are a few interesting add-ins for MCE (i.e. weather, RSS, etc.), but never really use them heavily either.

So back to MediaPortal; this looks very promising.  Here are some of the things I like about it so far:

  • very slick interface
  • over 100 plugins and extensions
  • you can actually turn off the annoying "My" prefix -- :)
  • built-in weather features are very nice (check out the cool GeoClock)
  • developed in .NET 2.0 (very cool indeed)
  • works with many remotes (including my MCE remote)
  • skinnable

From the look of it, there are a ton of other features that I haven't even discovered yet.  Needless to say I'll be looking into this quite a bit more and will definitely be trying it out as a replacement for MCE, since I can't see myself upgrading to Vista for my media center needs anytime soon.  (Not sure I'd want to anyways...)

If I had the time, I'd love to contribute to an OSS project like this...  along with a handful of others of course.  Those darn 24 hours just go by so fast... 

So anyways, check it out... it's a free download!

Now you can create you're own hammer factory factories...

 

Apparently MS will be providing a factory for creating your own application blocks for v3.0 of the Enterprise Library , should you desire to do so.  Reading Ayende's latest post on this and his link to this flashback post from Joel Spolsky, had me rolling on the floor laughing. 

Now I know MS has worked very hard on the Enterprise Library the past couple years, and from what I've seen it's quite comprehensive.  But I also think that's a weakness.  Because my experience with these kind of frameworks is that they try to solve every problem known to man in one package.  And the fact that each of the application blocks "complement" one another pretty much means you'll have to use a handful of them together for it to be effective, even though it might not be the best solution for that particular problem.

Meanwhile, there are perfectly good OSS options available that are just really good at one particular thing.  Take for example, log4net.  It's such a simple, lightweight and easy-to-use logging, dare i say, "framework".  But that's the thing.  It's one mini-framework instead of a framework of frameworks.  I could go on and on about all of the OSS tools that are making my life easier as a developer.

Another example is the Spring.NET framework.  Now yes, Spring.NET does offer solutions to a number of different problems, similar to the Enterprise Library.  But I've pretty much used Spring.NET exclusively for my dependency injection needs for a while now.  And the funny thing is that for the longest time, I thought that's all it did.  Now that is a sign of an easy-to-use framework.  Sure it offers features for AOP, web development, remoting and transaction management.  None of which I've used yet.  But I love the fact that it's not in my face about it.

Ok, so to make this post somewhat productive, here's a list off the top of my head of the OSS tools that are making my life easier these days:

I'm sure I forgot a few, but these are examples of tools that I'm finding solve their particular problem very well.

Websense is up to nonsense - Blocking Flickr

 

It seems Websense decided to block static.flickr.com in its latest database update #92635 on December 12th (as noted in this forum post).  This is bad news for people like me who are heavy users of Flickr for managing photos, including the screenshots I post to this blog.  Seems like an awful big hammer to use against the majority of those who use Flickr for the appropriate reasons.

I'm going to wait a few days before deciding whether to keep using Flickr for my blog screenshots, or start using an alternate location.  I really like using Flickr for managing all of my photos and screenshots, because it gives me a single place to keep everything organized, tagged, etc.

Let's hope Websense has some common sense and does something to resolve this mistaken blockage soon.

Increase productivity with ReSharper templates

 

(At the end of this article you'll find a set of links to download my current set of ReSharper templates)

Being a lifehacker and automation junkie, I'm always looking for ways to be more productive in everything I do, especially in how I develop software.  Whether it's automating my build and test process, or utilizing existing tools like NHibernate to reduce the tediousness of writing the same ol' ADO.NET code over and over, or keeping my hand off of the mouse, productivity is something I take pretty seriously.  After all, at the end of the day, we are supposed to actually deliver a high-quality piece of software in a timely fashion.

Well for the past year the #1 tool that has made me more productive in my development is ReSharper.  This is a tool that truly understands C#, and how developers write code.  I can't imagine developing without it anymore.  There are way too many features to talk about here, so I'll just defer that to their features page.  But what I want to focus on in this post is its templating features. 

Liven up your development

Live Templates are a great way to become more productive through micro-code generation.  You know, all those code statements that you seem to write over and over, perhaps in a certain way that you personally like.  Think of how many times we create a new List<T>, or throw a NotImplementedException, or write Assert statements, etc.  Well you can very easily encapsulate these kinds of statements in live templates along with placeholders for just-in-time customizations when you actually use the template in code.

Here's an example of how to create a simple template that can speed up writing your tests:

ReSharperLiveTemplates1

When you want to assert equality in one of your tests, just simply type aae, hit tab and bam.  Then just type the name of the expected value, hit tab, type value of actual value... you get the point.  Another thing I like about this is that it actually helps me write better tests by always providing a message with my assertions.  Back when I would actually type Assert.AreEqual, I would sometimes forget to include a message with my assertion, which, IMHO, is a very good habit to form.

Surround yourself with speed

Surround With Templates are great for code organization and just keeps the "flow" of writing code moving.  Just simply highlight the code you want to surround (using Ctrl-W is a great way) and then just hit Ctrl-Alt-J (that's the default anyway) and choose your template.  I find myself using the #region template more than anything to keep my code nice and organized.  But I'm just starting to tap into the power of these, and am actually finding use for them in other areas besides C# code.

For example, take a look at how you could create a couple templates to help with web development:

ReSharperSurroundWithTemplate1

ReSharperSurroundWithTemplate2

Notice the $SELECTION$ place holder which of course is what you want to surround and the $END$ placeholder is where the cursor will end up once the selection has been surrounded.  I can see huge potential for these is various types of files that we work with and I definitely plan on creating more as I need them.

File away those common code files

File Templates enable you to re-use those common code files your always creating, like of course classes and interfaces, but I also like them for test fixtures, build scripts, etc. 

Here's an example of one of my test fixture file templates:

ReSharperFileTemplate1

Wanna download my current set of ReSharper templates?

So far I've created quite a few templates for my personal development and I thought I'd share them with the community.  Some of them reflect the tools I'm currently use, like my set of NMock2 expectation and stub templates or my template for creating a private static logging variable for log4net.  And others are just some of the common code statements I'm always writing, like creating an anonymous delegate or just creating a static readonly string.

Here's a quick reference for some of my live templates:

NMock2 Templates

em - Method Expectation

ema - Method Expectation with Arguments

emr - Method Expectation with Return Value

emar - Method Expectation with Arguments and Return Value

egp - Property Getter Expectation

esp - Property Setter Expectation

sgp - Property Getter Stub

Test Templates

ntest - NUnit Test Method

vstest - VSTS Test Method

aae - Equality Assertion

ain - IsNull Assertion

ann - IsNotNull Assertion

ait - IsTrue Assertion

aif - IsFalse Assertion

Miscellaneous

anon - Anonymous Delegate

log - log4net private static variable used for logging in the current class

glist - Generic IList<T> variable

psrs - Public static readonly string

thrn - Throw a new NotImplementedException

 So finally, here's the download links:

Of course I'm always adding new templates, but the links above include my current set as of right now.  If there is interest, I'll keep these updated as I add new templates to my library.

Also, check out a few other bloggers who are offering up ReSharper templates that look very useful.

Anyone else have any cool ReSharper templates they care to share?

dnrTV! Episodes on Ruby with Venkat Subramaniam

 

Just watched the 1st and 2nd episodes Venkat gave about Ruby on dnrTV! and all I can say is WOW!  My only exposure to Ruby so far is a few Watir scripts I've written just for fun.  But now I really do see what all the hype is about.  I'm pretty passionate about writing code that is elegant and reads naturally so Ruby seems to be a perfect fit for me.  I'm very interested to start digging more into this awesome language, and of course the Rails framework.

Venkat is an excellent presenter and really had me on the edge of my seat about what cool thing he was going to do next in Ruby.  I'd highly recommend watching his episodes. 

He's also done a 3rd episode on some of the cool Ruby-ish type stuff you can do now in C# and in the soon coming C# 3.0 and LINQ.  Looking forward to watching that one soon.

Interesting series of articles on Domain-Driven Design

 

Just noticed that Ben Scheirman has an interesting looking series of posts going on about Domain-Driven Design and NHibernate.  Here's a list of the posts he's done so far (mainly for my reference):

I've only read the first one so far, but being a big fan of DDD and NHibernate, I'm looking forward to reading the rest of them.

Sermon Publisher - New application I'll be working on...

 

One of the things I'm blessed with is the opportunity to use the skills the Lord has allowed me to acquire, for Him in the media ministry at my local church.  I help manage the web site as well as publish our sermons to make them available to stream or download so that fellow believers can get fed from the Word of God wherever they have an internet connection.

Something I've wanted to do for a while now is automate many of the manual steps we perform during our sermon publishing process.  Here is a list of some of the steps we go through...

  • Record sermon to CD and digitally to a WAV file
  • Create and print CD labels with the sermon's date and title using a Word template
  • Encode the wav file to mp3
  • Upload mp3 to FTP server
  • Add sermon to our web site via an administrative site I built a while back
  • Burn wav and mp3 files to a cd as data files for backup purposes

So right now each of these steps are pretty much a manual one, usually using a different application for each one.  I can see a lot of areas for automation and it just so happens I develop software for a living.  :)

I plan to use the same iterative and TDD approach I use in my "day code" to ensure the quality of the codebase stays high.  So I thought I would share my experiences during the development of this application on my blog.

Stay tuned for the first installment...

.NET Developer Bootcamp In Edmonton...

 

Jean-Paul Boodhoo has just announced he'll be doing a deep dive boot camp class in .NET.  Based on the topics he has listed and the quality of his postings and sample code in the past, this is going to be an awesome class for the .NET community.  

I think .NET developers have needed this kind of class for a long time instead of the typical drag-n-drop, wizard-based development that most of the .NET classes include.  Looks like he'll really be diving into some much needed patterns and concepts that are essential for developing high-quality software.

And hey, you get an awesome book (one of my favorites) and the best producitivity tool for Visual Studio (IMHO) with the class.  Only 12 spots, so sign up quickly.

(If anyone in the Virginia area is reading this and you'd like to have this class down here, let him know...)  :)