Sunday, September 8, 2013

Categorizing your unit tests in C# (Visual Studio)

C# comes with a unit testing framework (at least in Visual Studio :). You write a test case like this:

public void TestMethod1() ...

When you have more than a few test cases, it is useful to break them into groups or categories; you can use:

  • Owner("name")
  • TestCategory("category")
  • TestProperty("name","value")
For example:

[TestMethod, Owner("Orlando"),TestCategory("stuff"),TestProperty("group","1")]
public void TestMethod1() ...

On the test explorer window, VS will show you your tests organized based on those values, and you can then select and run only those tests you want.

1 comment: