I just tweaked my previous entry's macro to be more context sensitive if you have a lot of test fixtures and do not want to run all of them in your solution.  If you are in a code window with a project, the macro will select that project and run the tests for it.  If you are in any other window, it will just run all the tests.  This could be useful if you have a number of projects in the same solution, all with test fixtures but only need to run a single test fixture instead of them all.

Sub RunProjectTests()
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)

Try
Dim
ProjectName As String
ProjectName = System.IO.Path.GetFileNameWithoutExtension( _
LastWindow.Project.FullName)
DTE.ActiveWindow.Object.GetItem(SolutionName + "\" + ProjectName).Select( _
vsUISelectionType.vsUISelectionTypeSelect)
Catch ex As Exception
'Fall back and just run all the test fixtures in the solution
DTE.ActiveWindow.Object.GetItem(SolutionName).Select( _
vsUISelectionType.vsUISelectionTypeSelect)
End Try

DTE.ExecuteCommand("TestDriven.NET.Client")
System.Threading.Thread.Sleep(150)
LastWindow.Activate()
End Sub

I'm not a Visual Basic programmer so these macros could blow up in weird ways if you use them in certain situations like opening a single file in Visual Studio without a solution.

It's getting late, so time for bed.

Tags: ,