Visual Studio 2012 RC – What’s new in Unit Testing

Visual Studio 2012 RC – What’s new in Unit Testing

Rate This
  • Comments 17

Unit Testing feature in Visual Studio 2012 has been very enthusiastically received by the developer community. Our focus during RC milestone was to respond to feedback we received from Visual Studio 11 Beta. This article talks about some of the new features that we have built during this milestone, many of which were driven by customer feedback.

 

Smart Test Discovery

Previously, when a test project was built, Test Explorer would perform an exhaustive search to discover the tests. Now we have implemented a Smart Test Discovery algorithm which significantly improves the time required for updates to appear on the Test Explorer Window. In fact, this is now so blindingly fast that for the first few times I would rebuild the solution just to make sure that discovery was happening.

 

Run Tests After Build a.k.a Continuous Test Runner

This feature was introduced in Beta and so well-liked that we have now moved it into the Test Explorer tool bar.

image

When this feature is turned on, the tests are run automatically after every successful build. If there are failed tests from previous runs, they are executed first.

 

Enhancements in Metro Unit Testing

1. Assert.ThrowsException

Previously, we were using the ExpectedException attribute on a Test Method to handle scenarios where the test would throw an exception. This approach has many limitations, primarily the ability to precisely identify the source of the exception. To address this we have added Assert.ThrowsException.

image

 

Test will fail if the specified exception is not thrown by the test code.

NOTE: Assert.ThrowsException is available only in Unit Test Library for Metro style apps. In conjunction, we have removed ExpectedException Attribute from Unit Test Library for Metro style apps.

 

2. Code Analysis

Code Analysis is now enabled for Unit Test Library (Metro style apps).

 

3. Portable Unit Test Framework library

The Portable Class Library project in Visual Studio 2012 RC enables you to write and build managed assemblies that work on multiple .NET Framework platforms. For example, you can create classes that contain shared business logic for desktop apps, Windows Metro style apps, and mobile apps, and you can then reference those classes from those projects.

We have converted the Unit Test Framework into a Portable Class Library.

 

Run/Debug Tests from Editor

We have enabled a shortcut menu in the Visual Studio Editor which allows you to run or debug the tests under the cursor.

image

 

Compatibility with Visual Studio 2010

Based on extensive feedback we received from customers, we have implemented the following features related to compatibility.

1. Test List Editor (.vsmdi) can now be opened in Visual Studio 2012 RC. This feature has been deprecated and you cannot run tests from this editor. You also cannot create new Test Lists in Visual Studio 2012 RC. We recommend that you use Test Categories to group tests and maintain test lists.

2. All Test Templates in Visual Studio 2010 (Ordered Tests, Generic Tests, Web Performance Tests & Load Tests) can now be added in a Test Project. They will be listed in the Test Explorer. You can run them from the Test Explorer.

 

Resources

We have added a number of articles in MSDN for Unit Tests. Check out the Verifying Code by Using Unit Tests link for an overview and pointer to various walkthroughs and detailed articles.

If you have feature suggestions for Unit Testing, you can log them at Visual Studio User Voice.

You can log bugs at Microsoft Connect.

You can also discuss your issues in MSDN Forums.

Leave a Comment
  • Please add 8 and 8 and type the answer here:
  • Post
  • I was wondering why  Assert.ThrowsException is only added for Metro style applications? Are you also going to add it to regular unit tests?

  • How about mocking frameworks? Will we ever see them for Metro style apps?

  • Why is Assert.ThrowsException() only available for Metro apps?

  • Nice enhancements! Thanks

  • @Wouter de Kort/@Thomas Eyde

    We have a backlog item to add Assert.ThrowsException to the regular unit test framework also.

  • In Beta, I was able to create F# project, add reference to Microsoft.VisualStudio.TestPlatform.UnitTestFramework? add some classes with TestClassAttribute and methods with TestMethodAttribute, and test runner will discover those tests. But it seems that it's not so easy now with this Smart Test Discovery as well as it was in VS2010. How can we force VS to discover test classes in certain project now?

  • Oh, I'm think I understand. In order to be discovered through Smart Test Discovery, assembly needs to explicitly reference Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll in code (in other words, to contain some assert). When I wrote previous post, my test method did not contain any assert and was only intended to check that there is no exception.

  • @Mathew - Do you expect Assert.ThrowsException to be implemented for regular unit tests in time for the VS 2012 RTM, or is that backlog item planned for a future version of Visual Studio? Count me in the group who really wants to see this included for non-Metro apps.

  • @Matt Ring

    Assert.ThrowsException in regular unit tests is planned for a future version. (not VS 2012).

    I have updated the hit count on the user story.

  • @Mathew Thanks for replying. That is unfortunate, but at least the new Test Explorer will have integrated support for NUnit (which does include that feature). So it is a partial win.

  • FluentAssertion will have all those nice fluent interfaces. Assert.... is urgly, why dont use FluentAssertions within VS2012, reinventing the wheel all the time will kill you guys someday.

  • Another question. VS2008/10 have a VSDMI file to show test list. I can create a tree to manage test cases, then select part of them to run, just like folers. Now in Test Explorer, all tests show in linear, without any levels. Is there any way to create a non-linear structure to manage them? I have 1000+ tests base on unit test frame. If there are no levels, it's very hard to control them.

  • @Johan, getting VS2012 Fakes working for Metro is something we will be investigating post RTM. Trust me, we want it too. :)

  • Hi,

    CreateUnitTest tab is missing from VS 11 RC also.

    Is there any workaround for that?????

  • good

Page 1 of 2 (17 items) 12