How to never be prompted to run last successful build when unit testing - unit-testing

I want to get rid of the dialog saying
There were build errors. Would you like to continue and run tests from
the last successful build
when I am running unit tests (I use test -> run -> all tests).
How do I do that? I already know how to disable it when running a normal project.
I also want to know how this can ever be a useful feature?

How do I do that?
You can't.
I also want to know how this can ever be a useful feature?
I find it useful when I am working closely with someone who is configuring test data. I can re-run tests to ensure new test data is valid, without having to worry about compiling any changes that I have done in the meantime.
For example if someone has changed some data in a database, I want to be able to run my tests to ensure that this new data is valid, and I want to be able to run the tests whether the current state of my code compiles or not.

For Visual Studio 2017 / MSTestV2 you can do:
Tools > Options > Project and Solutions > Build and Run
"On Run, when build or deployment errors occur:" "Do not launch"

Related

VS2017 Enterprise Code Coverage Doesn't Do It's Job

The code coverage tool in VS2017 enterprise no longer shows what application code is covered. Whether I run it on selected tests or all tests, it shows what code in the unit tests are covered, but shows the code actually being tested at 0%. When I first started using the tool it worked just fine and showed application code coverage. I only check coverage occasionally, so I'm not sure when it broke or what I might have done to cause the issue. I'm thinking that there is something in the Registry that is causing it since I haven't been able to find anything in Tools/Options/...
I installed JetBrains dotCoverage and it does the same thing even when I exclude the unit test project from the coverage session. I've tried to repair the VS installation. My next step is uninstall/reinstall. However, unless that cleans up the registry where I think the configuration error is, it will fail to address the problem.
So any suggestions on where I can look to figure this out would be appreciated.

How to get Debug output from unit tests in TFS 2015

When running unit tests locally in Visual Studio 2015, I can click on the Output hyperlink in the test results and gain access to all the Debug Trace output (as Standard Output) on the test output page.
However when using a build agent to build and test, I can't find any way to gain access to this output information. I've dug through every screen I can think of and nothing. All it shows is the Assert exception message and the stack trace.
Even if I download the .trx file it doesn't include the Console Output section.
Is there any way to get this output from a test run performed by an agent?
Also, some of my tests write additional information to the TestResults folder. The contents of this folder also appears to be excluded from the stored test information. Is there any way to get that as well?
The only other thing I can think of would be to have my tests write all their debug information to files then copy those to another folder as a build step. Seems kind of kludgy. If I remember correctly, the "old" TFS build process would save all this information automatically and it was available looking at test runs in Visual Studio.
Using System.Diagnostics.Trace.WriteLine() instead of System.Diagnostics.Debug.WriteLine(), you will get the information when run the test from TFS:

How do I run only ordered tests?

In Visual Studio 11, I'm facing a complex issue.
I'm using the Unit Test Explorer to run unit-tests. However, it shows both my normal unit tests and my ordered tests, which are basically collections of tests to run in a specific order too.
That doesn't work well for me, because I would love to have the setting "Run tests after build" on. However, as you would expect, what happens is that it runs both all my tests individually out of order and then runs my ordered test as shown in the picture below.
I would really love to be able to run only my ordered tests when the build finishes. I am not interested in third-party plugins/extensions to help me do this.
I ended up using a build server, and then configured my build configuration as follows, which will run all tests with the orderedtest file extension:

How to enable code coverage without using Visual Studio?

I have 80+ VS2010 solutions, each contains some unit test projects.
All solutions are merged into one big solution before build process.
All tests (or some test subset) are executed after the successful build.
I want to enable test code coverage for all tests to get exact code coverage for all output assemblies.
My question is: how to enable code coverage without using Visual Studio?
Note: I'm using TFS2010 (MSBuild) to build merged solution. VS 2010 Premium is installed on the build server. MSTest is used for test execution.
You can use JetBrain's TeamCity Professional. It is a CI server that supports executing unit tests and calculating code coverage. It is free for small installations.
I think you need to consider deploying a code coverage tool, see here for a comparison (provided you implement .net).We use NCover, which integrated in our TFS-Build in it's console variant and, although it's not trivial to set it up, we 're very satisfied with it.In this post I had briefly described how we inserted NCoverin our build, this might we useful to you even if you go with another tool.
If you create a Vsmdi file in your large solution (ms test will usually do this for you) you can use this to tell the build which assemblies you want to instrument.
This will only provide code coverage for assemblies that have tests run against them. If you're using testrun.config files to decide which tests you want to run, this should be all you need. The code coverage results should then be published to the build drop location
Edit:
This blog post looks like it covers setting up code coverage

Debugging unit tests with resharper

I've just started using resharper and I found a very annoying thing about it. When debugging a unit test, I try to step-into (F11) a method, but visual studio complains that source code is not available. The problem is that resharper is wrapping method calls with its own classes. Of course I can put a braeakpoint further in my source, but this is very annoying. Do you know if thereĀ“s a solution for this? By the way, I'm using NUnit to write my tests
Thanks
Federico
After some playing around I managed to recreate this on my setup (Xunit.net in resharper, visual studio 2008)... The steps I took to recreate this are:
Set the dll that contains the tests as the startup project (I know you don't need to do this, was just trying to get it to fail)
Put a breakpoint in the unit test
Push F11 (the shortcut key for 'step into' in my configuration)
This complains 'Cannot start test project 'RowanBeach.Crm.Domain.Test' because the project does not contain any tests.'
Run the 'Debug Unit Tests' command from the Resharper menu (I have this bound to a key combination on my machine)
This displays the 'No source code available...' message
Of course that's not how you should start unit tests from resharper! :) If that's what you were doing (or something similar), try this instead:
Don't bother setting the dll as the startup project - it doesn't need to be
build or rebuild the dll that contains the tests
set the breakpoint
Put the cursor somewhere in the source code for the unit test you want to debug to set it as the 'current context' unit test
Run the 'Debug Unit Tests' command from the Resharper menu (You might want to bind this to a key combination if you haven't already)
Hopefully, that should work
What type of tests are you running - NUnit? MS Test? Something else?
I've never found it difficult to debug tests using R# - just put a breakpoint in your test and go. What method are you trying to step into? I've generally not tried to step into the NUnit methods themselves (assertions etc) but stepping into your own code should be okay.
If you can come up with a quick example, I'd be happy to try it myself.