James Ko James Ko - 3 months ago 22
C# Question

How to run/discover tests from only one assembly in Visual Studio?

I have a moderately large VS solution that contains about 50 projects, half of which are tests. When I go to Test > Windows > Test Explorer after opening VS, the window takes minutes to load since it loads the tests from all ~25 test assemblies, which collectively contain thousands of test cases. However, I only want to run/debug tests for one project.

Is is possible to get the Test Explorer window to only discover tests for one assembly, and ignore the rest of the assemblies? Thanks.

Some more info that may be relevant: I'm using the xUnit testing framework in a .NET Core project.


You can unload all projects from the solution that you don't need to run tests from.
(Right click on the project in Solution Explorer and select Unload Project.)

Now Test Explorer only discovers and loads the tests from the remaining loaded assemblies.

You can also select multiple projects or a whole folder and unload them in one click. This also works when you apply a filter in the Solution Explorer. (For example if you want to unload all but one assembly containing something like ".Tests" in the name.)

It's even possible to open your solution multiple times in separate Visual Studio instances and apply different sets of loaded/unloaded assemblies to them.

This technique has the advantage that you don't need a separate solution for every combination of assemblies you want to run tests from and that you can keep your existing project references within your solution.