run tests in mstest without compiling/building

前端 未结 3 664
长情又很酷
长情又很酷 2021-02-19 09:35

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

相关标签:
3条回答
  • 2021-02-19 10:12

    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?

    0 讨论(0)
  • 2021-02-19 10:12

    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.

    0 讨论(0)
  • 2021-02-19 10:13

    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

    0 讨论(0)
提交回复
热议问题