Tuesday, March 10, 2009

Unit testing in Visual Studio 2008 Team System - part IV

Next (maybe not last) part re units tests inside VS.

[Ignore()]

Useful if one of test methods failed – you can use [Ignore()] attribute to decide later what to do with that test

So, our complete class code looks now as follow:







Refactoring

If we look at above code we can see lot of code duplication – refactoring is necessary.

We can appoint common block of code, it is worth to split tests on small 1 function methods.

To achieve that we will:

  • Define local members (source + destination)
  • Add Init() method marked by attribute [TestInitialize()] – executed before each tests
    (please note method need to be public)
  • Break down test methods on 3 atomic methods

After all our code shall look as follow:





Labels:

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home