Steve Smith's Blog

Musings on Software and the Developer Community

Run Tests By Project With MSTest

An annoyance I used to have with unit testing in Visual Studio is that it was often difficult to limit the number of tests I wanted to run.  In VS 2008 there are some improvements here, and the nicest one is the ability to right-click in a test and select Run Tests and have it run that unit test (or do so in a test class, and it will run all the tests in the class).  However, go over to the solution explorer and right click on a test project, and you won't find any Run Tests link there.  And trying Run Tests in a file but outside of a test class will kick off every test in the solution.  Sometimes that's what you want, but sometimes you just want to run the tests in one project.

The easiest way I've found to do this is to expand the Test View window.  By default my Test View window looks something like this:

Visual Studio Test View

Now, one solution would be to sort by Project, and then highlight the tests to run, and then click the little Run Tests button.  This is not exactly fun, easy, straightforward, or something I see myself doing on any kind of regular basis due to the hassle involved.  However, if you widen the Test View slightly (or click the little toolbar thingie in the top right), you'll see the Group By option:

 

Visual Studio Test View with Group By

Grouping by project will let you easily run the tests from one (or several) projects.  This is especially nice when you have a lot of test projects and some of them are integration tests (or load tests) that take a significant amount of time and all you want to run at the moment are your unit tests to ensure you haven't broken anything.

Run All Tests In Project

kick it on DotNetKicks.com

Tuesday, 08 July 2008

Comments

 avatar

Darren Neimke said on 09 Jul 2008 at 8:57 AM

Hi Steve, the way that I'd do this is to create Test Lists:

http://msdn.microsoft.com/en-us/library/ms182461(VS.80).aspx


ssmith avatar

ssmith said on 09 Jul 2008 at 11:33 AM

Hi Darren,

I used to go that route but found it's a pain as you keep adding more tests. You have to manually add them to the lists - there's no notion of smart lists where you can use rules to determine what tests are included. If I could make a list that included all tests in project ABC or all tests with the substring "Foo" then that might be cool. It was also annoying having to bring up the test manager - my Test View is docked with my Solution Explorer so it's pretty easy for me to get to it versus trying to find a tab with 50 other tabs open in the main panel.

So, yes, they work, but not as easily in my personal experience.


 avatar

Ben Scheirman said on 21 Jul 2008 at 12:21 PM

Sounds like we'll still have to install TestDriven.NET :)


Leave a Comment

Please join the discussion and share your thoughts.