Question

Visual Studio folder structure

I need some advice as to how I easily can separate test runs for unit tests and integration test in Visual Studio. Often, or always, I structure the solution as presented in the above picture: separate projects for unit tests and integration tests. The unit tests is run very frequently while the integration tests naturally is run when the context is correctly aligned.

My goal is to somehow be able configure which tests (or test folders) to run when I use a keyboard shortcut. The tests should preferably be run by a graphical test runner (ReSharpers). So for example

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

TestDriven.net have an option of running just the test in the selected folder or project by right-clicking it and select Run Test(s). Being able to do this, but via a keyboard command and with a graphical test runner would be awesome.

TestDriven.net test run output

Currently I use VS2008, ReSharper 4 and nUnit. But advice for a setup in the general is of course also appreciated.

Was it helpful?

Solution

I actually found kind of a solution for this on my own by using keyboard command bound to a macro. The macro was recorded from the menu Tools>Macros>Record TemporaryMacro. While recording I selected my [Tests] folder and ran ReSharpers UnitTest.ContextRun. This resulted in 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 was then bound to it's own keyboard command in Tools>Options>Environment>Keyboard.

However, what would be even more awesome is a more general solution where I can configure exactly which projects/folders/classes to run and when. For example by the means of an xml file. This could then easily be checked in to version control and distributed to everyone who works with the project.

OTHER TIPS

This is a bit of fiddly solution, but you could configure some external tools for each of group of tests you want to run. I'm not sure if you'll be able to launch the ReSharper test runner this way, but you can run the console version of nunit. Once you have of those tools setup, you can assigned keyboard shortcuts to the commands "Tools.ExternalCommand1", "Tools.ExternalCommand2", etc.

This wont really scale very well, and it's awkward to change - but it will give you keyboard shortcuts for running your tests. It does feel like there should be a much simpler way of doing this.

You can use a 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 a selection save file and run nunit using that.

I have never used this but maybe it could help....

http://www.codeplex.com/VS2008UnitTestGUI

"Project Description This project is about running all unit test inside multiple .NET Unit tests assembly coded with Visual Studio 2008."

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top