Executing Unit tests from Test Explorer in Visual Studio 2012

This document was originally published as http://www.mytechfinds.com/articles/software-testing/6-test-automation/70-executing-unit-tests-from-test-explorer-in-visual-studio-2012 by myself and has been reproduced here.

Visual Studio 2012 has deprecated the Test List Editor but has introduced a new window/pane called Test Explorer. The main job of this window is to discover “tests” in the currently opened solution. The idea is to give developers a easy way to execute unit tests frequently – they can set options on Test Explorer to execute unit tests on every build – not the TFS build, but the local build. So every time a developer hits F5 to run the application locally or F6 to build locally, the Test Explorer will discover, build and execute all the tests from that solution.

In order to set things right, all you have to do is add a new Unit Test project to the solution. Then write some unit tests on the application under test. That’s it!

To open the Test Explorer window, go to menu – Test --> Windows--> Test Explorer

http://www.mytechfinds.com/images/stories/edef377f1690_EF6D/testexplorermenu_thumb.jpg

If you have already built the solution, you will see all of your unit tests listed in this window.

http://www.mytechfinds.com/images/stories/edef377f1690_EF6D/testexplorerbeforeexecution_thumb.jpg

Click on Run All to run all the tests, you can also click on “Run on every build” button so that all the tests are executed every time you build the application and you don’t have to manually trigger this test execution.

The Test Explorer window gives detail information if a particular test is failing,

http://www.mytechfinds.com/images/stories/edef377f1690_EF6D/testexplorerErrorlog_thumb.jpg

Once fixed, and built again, the tests run again, it is designed for a iterative development and testing processes, very much useful if you are using TDD – Test Driven Development practice,

http://www.mytechfinds.com/images/stories/edef377f1690_EF6D/testexplorerafterexecution_thumb.jpg

Not all is good about this window though, it has less features compared to earlier Test List editor file, you cannot

  1. Organize your tests, by class, or type
  2. You can search but cannot really filter well unless you know the right keywords to filter, not a very practical solution when you have hundreds of unit tests developed by a team of developers and not only by you
  3. Export the results in any form, making it not so useful for the test team to execute tests from within VS environment
  4. There is a trx file generated for these runs, but not a separate for each run, the same gets overwritten for every run, so no result history of any sort

If I look at the Test Explorer window only made for developers to use TDD approach, then it’s a winner but not at the cost of removing powerful .vsmdi which was useful to devs as well as test.