How to run tests while debugging - visual-studio

I've been using ReSharper test runner in Visual Studio for quite a while, and there is one thing about it that I can't figure out.
I used to have some integrational tests in my solution that performed web requests to my local web server. I used to be able to launch my web application in debug mode, then launch a test with Resharper test runner within the same Visual Studio instance (that was currently running a debug session), and the test would run normally. The breakpoints in my application were hit, and I was able to debug the requests sent from the test.
However, when I was trying to do the same thing for a new project, the tests fail to launch. When I run any test, Visual Studio displays a modal window asking Do you want to stop debugging?. Why am I unable to run tests while having an active debugging session anymore? What does the ability to do this depend on? Visual Studio version? Resharper version? Unit testing framework (I'm currently using MSTest)?

I think I've seen this behavior before, it seemed to be driven by the fact that Resharper was feeling the need to always build my project/solution before running tests.
Try changing the Build Policy to Never (at first at least) from the Unit Test Sessions window:

Related

VS2013 Resharper always runs all tests

I got this strange problem with VS2013, NUnit and resharper
When I try to run a single test it always runs all tests in the project. It doesn't matter if I select Run or Debug or if I start it from the editor, unit test explorer or unit test session.
Only the test I started show up in the Unit Test session. No results from the other tests is visible but break points are hit in all tests.
The problem seem to start at random after editing a test. Have tried clean rebuilds and restarting Visual Studio but the problem remain.
Restarting the computer helps but only until it starts again after some edit.
Using VS2013 update 5, Resharper 10.01 and Nunit 3.0.1 (also tried 2.6.4)
Is this a Visual Studio, NUnit or Resharper problem?
Only other strange thing I noticed is that CTRL-Q (R# show documentation) does not work within test methods. It always show documentation for the test method not the variable or class the cursor is on.

Visual Studio Unit Test: Huge startup delay in debug Mode

I'm working on a big code project. When I try to run a unit test in debug mode using nunit on Visual Studio 2013 Ultimate, there's a consistent 40 second delay before the test runs. Now, once the test starts running, it runs as fast as I'd expect. And if I run the test in Release mode, there's no delay.
I know it's a local environment problem because other developers report no similar delay when they fire up a test on the project.
I've been unable to determine what's causing this delay. The only visual evidence is that the cursor changes to a spinning cursor. I've disabled everything in Options that looked like it might be demanding. I have NCrunch and Resharper installed, but both are disabled, so neither appears to be at fault.
Any suggestions?

Debugging code that's being tested in Visual Studio 2010

I am having some problems with a given test, that I'd like to debug the code that is being tested, while the test runs.
Is this possible?
If yes, how can I just debug this one test? I can only see options for running or the whole solution, or the whole set of tests in the current context or all impacted tests. I'd like to just run this one test, if possible!
I'm running Visual Studio 2010.
Put a breakpoint in the test and run the test with debug - use the test explorer to select just that test and "run selected".
See this MSDN page (How to: Run Automated Tests from Microsoft Visual Studio).

Trying to get selenium to start up using MSTest when running tests in Visual Studio

I'm trying to run selenium web tests in Visual Studio using MSTest.
I have a selenium process class, a selenium runner class and a web dev test class, as in this article:
http://keithbloom.wordpress.com/2009/10/16/running-selenium-tests-in-visual-studio/
I get the command prompt opening and I can see the selenium startup messages when I debug. However the first time I call selenium.Open everything shuts down. The MSTest error is reference not set to instance of an object?
And when I try and run it with Resharper (using MSTest), obviously all the paths are wrong :(
And for some reason Resharper takes about 2 mins to start the test where as MSTest takes 5s?
Anyone have any idea how to get these tools to actually work together?
I use Selenium with C# and NUnit quite regularly. I don't use MSTest for my tests but they tend to run quite quickly.
I have put together a C#/NUnit/Selenium tutorial a while ago. The URL for the Tutorial is http://www.theautomatedtester.co.uk/seleniumtraining/selenium_csharp_nunit.htm. I have never tried to run it with Resharper or MSTest but it should work fine. Just need to change the method attributes to the relevant MSTest items.

How can I get started using Nunit in my Visual Studio project?

I want to start using Nunit (finally), I am using Visual Studio 2008.
Is it as simple as importing Nunit into my test project?
I remember seeing a GUI for NUnit, does that do the exact same thing that a separate test project would do, except show you the pass/fail visually?
I like to add a link to NUnit in my external tools.
Under Tools->External Tools add NUnit
Title: &NUnit
Command: <path to nunit>
Arguments $(ProjectFileName) /run
Initial directory: $(ProjectDir)
After that you can quickly run it by compiling then hitting alt-t + n
Yes, that's basically it. Personally I find the unit test runner which comes with ReSharper to be excellent - and the tool itself is well worth the licence feel. Alternatively there's TestDriven.NET.
Having a test project which runs nunit-gui or nunit-console separately is all very well, but you really want the whole unit testing experience to be as seamless as possible. The easier it is to write and run tests, the more likely you are to do it - which is a very good thing. Don't underestimate the gradual build-up of frustration due to a slightly poorer user experience, flipping between windows etc.
NUnit is something that isn't inside Visual Studio 2008. It does have a console OR a graphical user interface (gui) that can be run both outside VS2008 OR can be attached to the process of VS2008 for debugging.
If you do want something inside VS2008 you need to have a third party pluging like ReSharper.
Edit: This has been answered in the past (not for VS2008 specificly but still relevant)
I've used TestDriven.NET with VS2005, and it has changed how I develop and test code.
You can run all of the tests on any class, module, project, or solution. You can also run a test in the debugger, which is tremendously useful to diagnose and fix issues when they crop up.
The GUI is nice, but if you run your tests often, you'll probably abandon it for a faster/integrated runner.
In any case, you have some options on how to run your tests:
NUnit.Gui.Exe -- you can run this & select your test project dll to run the tests. While it is open it will refresh when you build, so you can ALT-TAB to it & re-run your tets. Another technique I've seen is to set this application as the startup program for your test project. Then set your test project as the startup project and push F5.
Download & use TestDriven.net. This is fast and lets you run tests from a right click menu, while you're sitting on a test or at a node in the solution explorer. This is what I use mostly. I have it mapped to CTRL+T for quick access.
Resharper has a test runner as well. This gives you the GUI with red/green lights inside of visual studio. It also gives you a little icon next to each of your tests to quickly run them.
You can use the plugin NUnitForVS that is available here: http://www.codeplex.com/NUnitForVS
This integrates the test running and results in your VS 2008 IDE. We've been using it for a couple of months and it's working well for us.
You should also remember that with VS 2008 professional you can use the MS Unit testing tool that was previously only available in the team versions.
You can run it as external program, but as for me it is not very nice. I like, when test starts within the VS. So, if you have ReSharpe you can go to Tools -> Options -> Environment -> Keyboard and set the hot key for ReSharper_UnitTest_ContextRun. I set it to Ctrl + t.
I attach my nunit console program to the Post-build event so every time I build my project the tests are run without the need for third party tools (apart from NUnit). I'm using Visual Studio 2010, but I am pretty sure you can achieve the same behaviour in Visual Studio 2008.
To do this:
Open the project's properties window (the project containing the tests)
In the Post-build event command line add the line:
"C:\Program Files (x86)\NUnit 2.5.10\bin\net-2.0\nunit-console-x86.exe" "$(TargetDir)$(TargetFileName)"
Build the project and the output should be written to the Ouptput window (Build). It's important to choose the x86 version of the console runner.

Resources