Torbjörn Nomell’s blog

View Torbjörn Nomells profile on LinkedIn

Written by: Torbjörn NomellTDD
Enhance unit tests by checking coverage

When adding unit tests it can sometimes be hard to get an overview of how much code is covered, especially when adding tests to existing code.
Why not try a code coverage tool? I tried PartCover, it's free and open source software. Here's how to use it with Nunit.

• Click File -> Run target
• Edit settings


• Executable file: Full path to nunit-console.exe
• Working directory: Path to NUnit directory
• Working arguments: Path to test assemblies, delimited by spaces, DON’T forget /noshadow flag (to get source code from NUnit)
• Rules: Specify Assemblies to test and Namespaces eg. +[Assembly]Namespace (Start with +[*]* to get everything)
• Don't forget to save settings when satisfied
• Start
• Wait
• Browse the resulting tree
• Click Views -> View coverage details to see source code

 .NET 4? Be aware!
If your test assemblies are compiled for .NET 4 then things might not work.
That’s because NUnit doesn't support .NET 4 by default(?). I had to add the following to nunit-console.exe.config
<startup>
 <requiredRuntime version='v4.0.30319' />
</startup>

Coverage != Quality
Just remember that good code coverage cannot be interpreted as good quality of unit tests and the aim of 100% coverage have several drawbacks.



0 Comments
Write new comment

Written by: Torbjörn NomellTDD
Test all C# enum values with NUnit

I just tried to find a nice way to test all combinations of input parameters to a test case where one of the parameters is a C# enum. The thing is that I don't want to test the current range of enums but also those added in future. I found a blogpost about how to solve this with the TestCaseSource attribute. ValuesSource attribute could also be used if there are more input parameters to test. But the nicest way I could find out to do this was to extend NUnit with a new attribute.

[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)]

public class EnumValuesAttribute : ParameterDataAttribute

{

  protected System.Collections.ICollection data;

  public EnumValuesAttribute(Type anEnum)

  {

    this.data = Enum.GetValues(anEnum);

  }

 

  public override System.Collections.IEnumerable GetData

    (System.Reflection.ParameterInfo parameter)

  {

   return this.data;

  }

}

Now our tests can look like this:

[Test]

public void Test(

  [EnumValues(typeof(MyEnum))]MyEnum val,

  [Values(true,false)]bool isNewUser)

{

}

 



0 Comments
Write new comment

Written by: Torbjörn Nomell.NET
NServiceBus

Had the opportunity to hear Udi Dahan and Andreas Öhlund talk about NServiceBus last week. To really understand what NServiceBus is all about I think I’ll have to download it and fiddle with it or maybe read some more blog posts. What I did understand that it’s a really cool architectural component that can simplify and enhance the systems we build. Not to mention sagas, which I have to dig in to a lot deeper. Udi is a good speaker and he can really captivate the audience.



0 Comments
Write new comment

Written by: Torbjörn Nomell.NET
CQRS and Event Sourcing Seminar

I went to a seminar at Avega yesterday. The speaker was Andreas Öhlund and the subject was the Command-Query separation principle and Event sourcing. I’ve read some blogs about CQRS and we’re using a subset of the principle in my current project. Andreas gave us a walkthrough of the principle.

After the break he moved on to Event Sourcing which is totally new for me, this was an eye opener of a different way to think. I won’t try to explain anything here but if it sounds interesting try google it or read some blog posts of Greg Young.

I wonder how adopted these ideas will be in let’s say five years. Probably we will see the amount of CQRS frameworks evolve, like NCQRS, I haven’t had  a chance to examine NCQRS yet but that will be interesting.



0 Comments
Write new comment

Written by: Torbjörn NomellMisc
Utvecklingskonferenser nära dig

Tech Days
29-30 mars
Örebro, Sweden
http://www.microsoft.com/sverige/techdays/sessioner.aspx

 

Scandinavian Developer Conference
4-5 april Göteborg 2011
http://www.scandevconf.se/

 

DevSum Stockholm
18-20 maj
http://devsum.se/
Corner Stones DevSum conference

 

Norwegian Developers Conference
8-10 june, Olso, Norway
http://www.ndc2011.no/
NDC is Norway’s largest conference dedicated to .NET and Agile development.

 

Øredev 2011
7-11 November

http://oredev.org/2011



0 Comments
Write new comment



TalkActive Blog - Copyright 2008 - Talkactive ApS - all rights reserved.