10

Using Visual Studio 2010, is there a way to run all unit tests in a solution automatically after building the solution locally?

6 Answers 6

3

for anyone still reading this, use this visual studio extension:

http://visualstudiogallery.msdn.microsoft.com/c074d3c6-71e2-4628-9e7c-7690e706aef4

It does exactly what you want, i.e. run your tests after a local build. Failed tests will show up as a build error in your error window...

Why is this not out-of-the-box functionality @Microsoft? :)

Sign up to request clarification or add additional context in comments.

Comments

2

You could also try this addon: http://ox.no/software/continuoustesting

2 Comments

I like this solution, but, it seems that it will only run the unit test from the first test project (assembly) that it finds (atleast that's what it appears to be doing).
Didn't know that sorry. That must be an issue in a lot of cases.
2

One of these macros should fulfill your needs:

    Sub RebuildAndTestAll()
        DTE.Solution().SolutionBuild().Clean(True)
        DTE.Solution().SolutionBuild().Build(True)
        DTE.ExecuteCommand("Test.RunAllTestsInSolution")
    End Sub

    Sub BuildAndTest()
        DTE.Solution().SolutionBuild().Build(True)
        DTE.ExecuteCommand("Test.RunAllTestsInSolution")
    End Sub

Comments

2

This page describes running automated tests from the command line:

http://msdn.microsoft.com/en-us/library/ms182486.aspx

MSTest.exe is the program you need, but there's much more info on the MS web site.

Comments

1

You could record a macro to do it. In the macro, you would run the build and then start the unit tests. Then you could just run the macro to do it all in one step. Check Tools->Macros for more details.

EDIT You can also record keyboard shortcuts for the macros, and I think you can use existing key sequences, such as CTRL-SHIFT-B for build. So if you wanted to override the default behavior of CTRL-SHIFT-B, this would be one way.

5 Comments

I would prefer to not affect how we build when we are developing. In other words, I want the unit tests to run when a developer compiles a solution via Build -> Build Solution.
@Rick D - As far as I know, there's no way to alter the behavior of Build->Build Solution.
@Rick D - However, see my latest edit for a partial solution.
Thanks dcp... looks like the way to go.
Build -> Build Solution can be changed via Tools -> Customization
0

For those who want to test in Visual Studio 2012 here's a very interesting addon:

TestAfterBuild

http://www.youtube.com/watch?v=t7X_-eKDhwk

http://visualstudiogallery.msdn.microsoft.com/5dca9c5c-29cf-4fd7-b3ff-573e5776f0bd?SRC=VSIDE

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.