jaekie
jaekie

Reputation: 2303

Unit Testing on build

Any better way to do this? I've used the Continuous Testing AddIn from visual studio gallery, but does not work with SolutionFolders..

so I just added a "Post Build Macro" with

"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\MSTest.exe" /testcontainer:"$(TargetPath)"

Works great, but when there are errors, all I get is an exit code, is there a better way to do this?

Upvotes: 2

Views: 317

Answers (1)

Jaguir
Jaguir

Reputation: 3690

  1. Open the Macros IDE (Tools > Macros > Macros IDE).
  2. Open the EnvironmentEvents module.
  3. Add this code:

.

Private Sub BuildEvents_OnBuildDone(ByVal Scope As EnvDTE.vsBuildScope, ByVal Action As EnvDTE.vsBuildAction) Handles BuildEvents.OnBuildDone
    RunTests()
End Sub

Private Sub RunTests()
    ' Only run tests if there were no errors during build. 
    If (DTE.ToolWindows.ErrorList.ErrorItems.Count = 0) Then
        ' MSTest
        DTE.ExecuteCommand("Test.RunAllTestsInSolution")
        ' ReSharper
        'DTE.ExecuteCommand("ReSharper.ReSharper_UnitTest_RunSolution")
    End If
End Sub

Upvotes: 2

Related Questions