TechBubbles Microsoft Technology BLOG

Unit testing improvements in Visual Studio 2012 Update2

This post explains the features that have been introduced for unit testing in Visual Studio 2012 update 1 and 2. Visual Studio 2012 update 1 and 2 introduced many new features for testing which can be read here. New features grouping and filtering tests by project, by trait or by class enables testers to work with lots of tests easier.

image

Now developers can group their tests in test explorer according to which project they are in, what classes the test methods are in or by test trait. Test trait is a test property of a given unit test and several are available in MS test unit test framework. MS test finds the attributes used to mark test methods for specific traits. A test method can be attributed with an owner , priority or with test category.

[Test Class]
public class TestClass1
{
    [Test Method]
    [Owner("James")]
    [Priority(0)]
    [TestCategory("Slow Running")]
    public void MsTestMethod1() { }
}

Additionally developers can create their own traits using their test property attribute for MS Test

[Test]
[Property("Test type", "ATDD")]
public void NunitTest1() { }

Other unit testing frameworks may use other means of defining traits. example Nunit uses property attribute and Xunit uses trait attribute.

Filtering unit tests in test explorer allows developers to focus on just those that are important to them. This feature useful for solutions with hundreds of tests.

image

This helps running tests quick and easy. With Playlists developers can create custom lists mapping to exactly those test cases to run in specific situation.

image 

Improvements are also been made to the Windows 8 store applications by simplifying complex testing scenarios. Windows 8 store applications use Async, Assert.ThrowsException of  T enables the developers to test when an exception is thrown in Async lambda expressions.

[TestMethod]
public void TestMethod1()
{
   Assert.ThrowsException<NullReferenceException>(
        ()  =>
       { 
          throw new NullReferenceException();
       });
}

Enable passing data in test methods, executing one pass throw the test method for every row of data.

image 

Test methods can also be decorated with UITestMethod attribute forcing unit test to execute on Main UI thread.

image

More on this topic can be read here

About the author

Kalyan Bandarupalli

My name is kalyan, I am a software architect and builds the applications using Microsoft .NET technologies. Here I am trying to share what I feel and what I think with whoever comes along wandering to Internet home of mine.I hope that this page and its contents will speak for me and that is the reason I am not going to say anything specially about my self here.

Add Comment

TechBubbles Microsoft Technology BLOG

Follow me

Archives

Tag Cloud