One thing that has always bugged me about TestDriven.NET is that there does not seem to be a way to run all the tests in your entire solution. Nor is there one to run all the tests in the project of the current file you are in. The Visual Studio commands TestDriven.NET.Client and TestDriven.NET.RunTests commands are always context sensitive. If you are in a specific test method, then TestDriven.NET only runs that single test. If you are in a TestFixture but outside any method, then it runs the whole fixture. You can always right click in the Solution Explorer and pick Run Tests but I like to keep my hands on the keyboard as much as possible.
Tonight, I had had enough and went searching. According to Scott Hanselman, at one time, there was a TestDriven.NET.Solution command which sounds like it would do what I wanted but it appears to be long gone. I found a blog entry from 2006 by Joe White that uses a Visual Studio macro to make TestDriven.NET behave. I had never used the Macro Explorer before but it is pretty simple. Using Joe's macro as a base, I came up with:
Sub RunAllTests()
Dim LastWindow As Window
LastWindow = DTE.ActiveWindow
DTE.Windows.Item(Constants.vsWindowKindSolutionExplorer).Activate()
Dim SolutionName As String
SolutionName = System.IO.Path.GetFileNameWithoutExtension( _
DTE.Solution.FullName)
DTE.ActiveWindow.Object.GetItem(SolutionName).Select( _
vsUISelectionType.vsUISelectionTypeSelect)
DTE.ExecuteCommand("TestDriven.NET.Client")
System.Threading.Thread.Sleep(150)
LastWindow.Activate()
End Sub
Joe automatically switched to the output window at the start of the macro, I removed this because TestDriven.NET already does this. Which brings up another annoying feature of TestDriven.NET, I wish I could turn it off and just have it post to the status line. I store the last window for later because the macro has to switch the focus to the Solution Explorer to run the command. The Sleep call is so that TestDriven.NET has enough time to think the context is set to the root of the Solution Explorer instead of wherever you happen to be. Without it, it switches back and forth too quickly on my computer and TestDriven.NET just runs the command in whatever context it determines. You may need to tweak the number if your computer is faster or slower. I found it would still work at 100 but not at 50, so I just set it to 150 to be sure. It switches fast enough that it is not troublesome to my workflow.