35

Whenever I run unit tests, Visual Studio builds to make dlls and exes even when I modified nothing in code.

How can I make so that Visual Studio doesn't build when I didn't make any changes before running the unit tests?

prosseek
  • 182,215
  • 215
  • 566
  • 871

3 Answers3

16

Open the Tools -> Options... menu item, expand the Projects and Solutions node, click on Build and Run, and in the On Run, ... dropdown, select Never Build.

competent_tech
  • 44,465
  • 11
  • 90
  • 113
  • 9
    It doesn't work with unit test. With the setup, it still builds when I run unit test. – prosseek Dec 07 '11 at 15:05
  • 5
    This setting disables the compilation step for running the project (F5) -- I've modified my settings with the above and it seems like it still compiles. – bryanbcook Dec 07 '11 at 20:01
  • 2
    If something has been modified then of course we want the IDE to rebuild the resources. The PM was asking about when there haven't been any changes to the source. – Rabbi Jun 27 '13 at 13:39
  • 4
    @prosseek Why did you select this answer then? – IEnjoyEatingVegetables Dec 29 '17 at 13:46
4

What are you using to run your tests?

If you are using VS try Re-sharper. The test runner has the ability to specify what to do straight from the test runner. It has settings for Automatic, Automatic (Whole Solution), Always Build, and Never Build. The automatic setting seems to work well. If you don't have re-sharper you should get it. Its awesome and can save you a ton of time.

Brett Allred
  • 3,459
  • 26
  • 30
2

This is an old question, but I keep seeing people ask it and the issue is still true in VS2017, and it's also true of other test frameworks (Xunit, etc) run from within VS.

The way to do it is to not run your tests from within VS, but from within the console runner. This doesn't change the behavior of VS, but circumvents it. If you aren't in VS, then it can't recompile. If you're using ReSharper, as Brett says, it has one.

If you aren't using ReSharper, for MSTest, you can start here. https://msdn.microsoft.com/en-us/library/ms182489.aspx

If you aren't using ReSharper, for XUnit, you can start here. https://xunit.github.io/docs/getting-started-desktop.html#add-xunit-runner-ref

CindyH
  • 2,986
  • 2
  • 24
  • 38
  • 3
    Please don't post identical answers to [multiple](http://stackoverflow.com/a/45198342) [questions](http://stackoverflow.com/a/45198282). Post one good answer, then vote/flag to close the other questions as duplicates. If the question is not a duplicate, *tailor your answers to the question.* – Paul Roub Jul 19 '17 at 18:50