How to run (single) tests in different folders / projects separately in Visual Studio?

Visual studio folder structure

I need some tips on how I can easily separate test runs for unit tests and integration test in Visual Studio. Often or always I structure a solution, as shown in the figure above: separate projects for unit tests and integration tests. Unit tests are performed very often, while integration tests are naturally performed when the context is correctly aligned.

My goal is to somehow configure which tests (or test folders) to run when using a shortcut on the keyboard. Tests should preferably be performed by a graphical test runner (ReSharpers). For example,

  • Alt + 1 runs tests in the BLL.Test project,
  • Alt + 2 runs tests in the DAL.Tests project,
  • Alt + 3 launches both of them (that is, all tests in the [Tests] folder and
  • Alt + 4 runs the tests in the [Tests.Integration] folder.

TestDriven.net has the ability to run only the test in the selected folder or project by right-clicking it and selecting Run Test (s). Being able to do this, but using a keyboard command and with a graphical test runner would be great.

TestDriven.net test run output

I am currently using VS2008, ReSharper 4 and nUnit. But advice for installation in general, of course, is also welcome.

+4
source share
4 answers

I really found this solution for myself using the keyboard command associated with the macro. The macro was recorded in Tools> Macros> Record Temporary Macro. During recording, I selected the [Tests] folder and ran ReSharpers UnitTest.ContextRun. This led to the following macro,

Sub TemporaryMacro() DTE.Windows.Item(Constants.vsWindowKindSolutionExplorer).Activate DTE.ActiveWindow.Object.GetItem("TestUnitTest\Tests").Select(vsUISelectionType.vsUISelectionTypeSelect) DTE.ExecuteCommand("ReSharper.UnitTest_ContextRun") End Sub 

which then attached its own keyboard command to it in the menu "Tools"> "Options"> "Environment"> "Keyboard".

However, even more surprisingly, this is a more general solution where I can fine-tune which projects / folders / classes to launch and when. For example, using an xml file. Then it could be easily checked in version control and distributed among all who work with the project.

+2
source

This is a slightly hesitant solution, but you can configure external tools for each group of tests that you want to run. I'm not sure if you can run the ReSharper test runner this way, but you can run the console version of nunit. After installing these tools, you can assign shortcuts to the commands "Tools.ExternalCommand1", "Tools.ExternalCommand2", etc.

It does not scale very well, and is inconvenient to change - but it will give you keyboard shortcuts to run your tests. He feels that there should be a much simpler way to do this.

0
source

You can use the VS macro to parse the XML file, and then call nunit.exe with the / fixture command line argument to specify which classes to run or generate the save selection file and run nunit using this.

0
source

I never used this, but maybe this could help ...

http://www.codeplex.com/VS2008UnitTestGUI

"Project Description This project is designed to run the entire unit test within several .NET Unit tests encoded using Visual Studio 2008."

0
source

Source: https://habr.com/ru/post/1276353/


All Articles