38

In my Visual Studio solution, I have about a dozen projects, several of which contain unit test methods (tagged with the TestMethod attribute), with several hundred test methods spread across those projects.

From within Visual Studio, I'd like to run all of the (100+) tests in one particular project in the solution, without running the tests in the other projects in the solution.

Ctrl+R, A doesn't do what I want, since that runs all tests in the entire solution. I also don't see any options to run tests in a particular project in the Test menu, in the Test Explorer window, or in the right-click context menu for a project in the Solution Explorer window.

I'm using Visual Studio 2013.

What's the best way to get Visual Studio to run all of the test methods in a particular project?

Jon Schneider
  • 25,758
  • 23
  • 142
  • 170

1 Answers1

64

After some additional poking around the UI, I figured out a decent way to do this:

  1. Open the Test Explorer window. (Test menu > Windows > Test Explorer)
  2. Click on the little down arrow just to the left of the search field.
  3. From the context menu that appears, select Project. The Test Explorer window contents change to be grouped by project in a 2-tier hierarchy.

Test Explorer filter menu

  1. Right-click on the desired project.
  2. From the context menu that appears, click Run Selected Tests.

Test Explorer project context menu

I'd still like a reasonable way to do this with only the keyboard, though!

Jon Schneider
  • 25,758
  • 23
  • 142
  • 170
  • Only with the keyboard? They I would go for mstest in the command line. Just run the test assembly you are interested in! :-) Are there any specific reason why you don't want to run all test? Are they slow...? I usually only have one test project per solution, but I also aim to have small solutions for then it is not a problem... – Jocke Nov 11 '15 at 21:54
  • @red888 Good question! Maybe ask that as a new question (assuming it hasn't been asked before)? – Jon Schneider Aug 15 '17 at 14:08
  • 1
    Doesn’t this require test discovery to run first? If I do this, it doesn’t notice newly written tests… https://i.imgur.com/94d4lKm.png – binki Jan 22 '18 at 01:34
  • 2
    Great to know. Adding a right click option on a project or folder to 'Run tests' would make things a lot more intuitive though. – Carra Mar 02 '18 at 14:49
  • I use keyboard shortcuts for loading and unloading Projects. I put all the test projects in a Solution folder so I can turn them all on or off. The commands are Project.UnloadProject and Project.ReloadProject. I don't remember if they have defaults. – Programmer Paul Dec 06 '19 at 23:27
  • Is there a way to do this with Visual Studio 2019? – Aaron Franke Aug 25 '21 at 18:26