19

In our solution we have several test projects. Most of them contain unit tests that run fast but some are for integration, acceptance and UI tests which take quite some time to finish. Now I'd like to have a convenient way of running only the unit tests. Either by using the hotkey to run all or using the new feature to run tests after each build.

Unfortunately VS also runs all the slow tests as well. In VS10 I grouped the tests in Test View by project and selected only the ones containing unit tests. It's not as easy as I wished it to be but at least it was possible. Now there doesn't seem to be a way around running all tests in a solution.

The only alternative that I see at the moment is to remove all but the unit tests from the solution but this would limit the refactoring capabilities.

So does anyone know how to easily group and run only unit tests in the new VS?

Cybermaxs
  • 24,378
  • 8
  • 83
  • 112
devdumbblind
  • 193
  • 1
  • 1
  • 5

5 Answers5

9

In Visual Studio 2012 Update 1 CTP, Test Explorer has added the option to group tests by Project or Traits (Categories).

Please go to this link to see what's new there.

Cybermaxs
  • 24,378
  • 8
  • 83
  • 112
Qing Zhao
  • 106
  • 2
8

You can use the search filter in Unit Text Explorer.

enter image description here

In the new Test Exlorer shipped with 2012, you can group tests by 'Test Results', 'FileName',... etc but in RTM build group/search by 'TestCategory' is not present from Test Explorer. However there is a filter in commandline and TeamBuild based on TestCategory (Running selective unit tests in VS 2012 RC using TestCaseFilter) in VS2012.

From a member of VS dev Team, they understood the importance of this missing feature. It is in the backlog, and it should be available in furutre builds/updates.

The following blog provides more details: http://blogs.msdn.com/b/vikramagrawal/archive/2012/07/23/running-selective-unit-tests-in-vs-2012-rc-using-testcasefilter.aspx

Cybermaxs
  • 24,378
  • 8
  • 83
  • 112
3

As of Visual Studio 2012 Update 2 (currently on CTP) now we are able to run a subset of unit test using "Playlists" or based on "Lists & Classes". More information here: http://blogs.msdn.com/b/visualstudioalm/archive/2013/01/30/first-ctp-for-visual-studio-update-2.aspx#playlists

Original Answer:

AFAIK, The new unit testing framework in VS2012 "supports selective execution based on filtering condition through TestCaseFilter". Unfortunately, currently there is not support to do this through the user interface but it is in the product group's backlog. You can use this approach through Test Build or command line. Please refer to the following blog: http://blogs.msdn.com/b/vikramagrawal/archive/2012/07/23/running-selective-unit-tests-in-vs-2012-rc-using-testcasefilter.aspx

EDIT: Following the MSDN documentation to use test categories to group tests.

http://msdn.microsoft.com/en-us/library/dd286595.aspx

Also, refer to this question: How to exclude certain tests in the Visual Studio 2012 Test Runner?

It shows an example of filtering based on the test path.

Community
  • 1
  • 1
Mauricio Aviles
  • 1,074
  • 9
  • 24
2

I'd recommend using TestDriven.Net. Group all Unit Testing projects in one solution folder, and all other tests in another. Then just right click the "Unit Tests" folder and choose "Run All Tests". I always favor this great test runner of the VS native testing tools.

Another approach is using NCrunch - It runs all you tests in the background while you code. It handles integration tests pretty well, as they run in parallel, in the background so it doesn't block you (you also choose which test projects are run). One catch though - I believe it doesn't support VS2012 yet, but probably soon.

seldary
  • 6,186
  • 4
  • 40
  • 55
1

I was also missing this feature... (We did the same as you did: grouping by project or sometimes by namespace). But I found that I could somehow workaround this using the test explorer search capabilities:

https://msmvps.com/blogs/deborahk/archive/2012/09/16/searching-and-grouping-in-vs-2012-test-explorer.aspx

In my case I could identify the specific tests I needed to run using the search filter on FullName (use dropdown on search box, or type FullName:"UnitTest")

Its not the same, but it works for me

Tjipke
  • 408
  • 3
  • 12