run tests in mstest without compiling/building
Asked Answered
Y

4

20

is there a way? do I have to wait for building every time I start the test? I want to build from visual studio not from test

thanks

Yasui answered 6/4, 2009 at 6:53 Comment(6)
I'm not sure what you are asking. Visual Studio always has to compile your code prior to running your unit tests because your tests are really just .NET IL like your application code.Support
and what if I compile my code and then run test 1,2,3,4 times...every time MSTEST builds my code again..I do not want that, I want for my tests to be speed as they can..somewhere on stack I red that nUnint can do this...Yasui
I'm having this problem all of a sudden, also.Nickels
Marko.. I have the same problemDunedin
I am not able to reproduce this. When I run 'mstest.exe /testcontainer:[testproject.dll]' no compiling/building occurs.Vanillic
This question is really hard to search for because most results are about adding tests to the build process. Our project at work recently started rebuilding every time I run tests with no code changes so I'll ask around to see if anybody knows what happened.Marilumarilyn
A
13

Any time your code changes and you run your test it is going to do a build... so technically you can run your test over and over again and they will only build the first time, but once you run your test why would you run them again without making a code change?

Couple of things that I use that make your test run faster are:

  1. Check the box for "Only build startup projects and dependencies on Run", located Options->Projects and Solution->Build and Run.

  2. Learn the short cut keys
    a. "Ctrl+R, T" Runs test in current context, so if your cursor is inside a test method it will only run that test, but when you do it inside of a non test class it will run all of your test.
    b. "Crtl+R, Ctrl+T" Debug test same except debug.
    c. Others can be found here, those are 2008 if you need to reference others you can find them via google.

  3. Make sure your test are not calling the database or other time intensive resources, use mocking and stubbing.

  4. Run only small sets of test, ie if I am working in a service class I run only the service class test.

Edit: Reading your question again if you want to build and not from a test you can just go to the menu and click Build->Build Solution or press F6. Also it would be helpful if you indicated which version of visual studio you are using because 2010 is different in the sense that you have to click refresh. Either way are you able to clarify?

Amazonas answered 23/9, 2010 at 18:53 Comment(4)
You might run them again if you weren't expecting an error but had one, or you had an error and your debug point missed it, or something along those lines.Augmentation
That could be true... Run once see error, Then debug to step through. I didn't think of that scenario.Amazonas
I am using Visual Studio 2008.Yasui
Hm, it is strange...I tried now to run tests, I haven't used MSTest for some time(switched to NUnit) and I can see that is not build project every time, just once at the start. The same is when I build project manually and then start tests. But it was not like that when I've asked question? Is this came with an update or something?...it is very strange...Yasui
G
3

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.

I don't know how to make VS stop building all the time. But I do know how to circumvent the compile - run your tests from a console runner, not from within VS. If you're using ReSharper, 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

Gertrudgertruda answered 19/7, 2017 at 18:22 Comment(0)
S
2

Any changes to source code cause compilation, because in order to run tests VS needs up to date DLL with tests.

If you have already compiled project then you can run test multiple times without compilation.

PS: I run MSTest using TestDriven.NET as for me it is faster.

Syllable answered 24/9, 2010 at 5:59 Comment(0)
W
0

This answer works for me. I'm using Visual Studio 2022 and MSTest2 (with all the latest updates).

Menu bar

Tools -> Options -> Projects and Solutions -> Build and Run

Dropdown: On Run, when projects are out of date:

Never build

enter image description here

Warford answered 7/11, 2023 at 0:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.