I've seen many a demonstration where the presenter is using a lightweight test runner like TestDriven.net which allows for the execution of units tests without a lot of GUI fanfare. A few months ago I was having trouble with the Resharper test runner in Visual Studio (for some reason it stopped building my assembly before executing the tests) and so I wrote a macro that allows you to run tests from the context of the current cursor location. I’ve mapped this to my F12 key for quick execution.
Here is the Visual Studio macro that I wrote. It uses Resharper's unit test context run feature. Simply position the cursor inside a namespace, class, or test, and when you invoke this macro it will build the assembly in context, and then proceed to run all the tests found in the current cursor context.
Private WithEvents testLaunchBuildEvents As BuildEventsPrivate OverallBuildSuccess As BooleanPrivate PayAttention As BooleanSub BuildAndTestCodeContext()If (testLaunchBuildEvents Is Nothing) ThentestLaunchBuildEvents = BuildEventsEnd IfOverallBuildSuccess = TruePayAttention = TrueDTE.ExecuteCommand("Build.BuildSelection")End SubSub SolutionBuildDoneForUnitTestContextRun(ByVal Scope As EnvDTE.vsBuildScope, ByVal Action As EnvDTE.vsBuildAction) Handles testLaunchBuildEvents.OnBuildDoneIf Not PayAttention ThenExit SubEnd IfPayAttention = FalseIf OverallBuildSuccess ThenDTE.ExecuteCommand("ReSharper.ReSharper_UnitTest_ContextRun")ElseBeep()End IfEnd SubSub SingleProjectBuildDoneForUnitTestContextRun( _ByVal Project As String, _ByVal ProjectConfig As String, _ByVal Platform As String, ByVal SolutionConfig As String, _ByVal Success As Boolean) Handles testLaunchBuildEvents.OnBuildProjConfigDoneOverallBuildSuccess = OverallBuildSuccess And SuccessEnd Sub
0 comments:
Post a Comment