In VS2010, if I click on
Test->Run->All Tests in Solution (CTRL+R,A)
All of my tests will run and I'll be able to see what tests passed and what tests failed.
If I use the shortcut (Ctrl+R,A), then it will break when an exception is thrown.
Why is this experience different? How can I run all my tests through no matter what without going to the menu bar?
The chord "CTRL-R, A" executes
Test->Run->All Tests in Solution (CTRL+R,A)
The chord "CTRL-R, CTRL-A" executes
Test->Debug->All Tests in Solution (CTRL+R,CTRL-A)
So the fact is that you aren't using the shortcut you think you are.
Related
My problem is that my unit tests fails from time to time. Most of the times it is successful.
I would like to run it X amount of times or just repeat the test case until it fails.
What I can do is to just click on the test and rerun it once more even though it has been successful run, but that is time consuming.
I have had a look in Visual Studio in "Test Explorer" and Resharper "Unit Test Session", but I can find a smart way to rerun all test until it fails.
Is there another way?
Best Regards,
Hans
I see you mention you have ReSharper - in the Resharper unit test session window you can select the test you are interested in, then click the drop-down next to the Run button and there is a "Run Unit Tests Until Fail" option
Also, see here
I'm running unit tests on my GetModelAsync() and CreateModelAsync() methods in VS17. I then run Assert.Equal checks on the model fields to ensure they match the expected values.
I want to be able to see the final state of my models, which will help me determine why a test is failing or allow me to manually check my models. I'm thinking something similar to tracking variables in the debugger would make sense, although I don't want to actually run the debugger.
Is there a way to do this?
You can write to the console in your tests and it will show up in Test Explorer. You may want to serialize complex objects to JSON first before doing this. For example:
Console.WriteLine(JsonConvert.SerializeObject(myObject));
Note, for Visual Studio's built in test runner, you have to go through a few steps to see the console output. In the Test Explorer window, click the name of your test, then in the results panel click the Output link, which will open a separate window to show the console output. It's all very unintuitive.
I have a series of Google Unit Tests that are launched via a bat file. Some of these tests are broken and a window appears when they run:
Microsoft Visual C++ Debug Library
Debug Error!
... Info about error
This window waits for a user to press Abort, Retry, Ignore. Of course, this halts my test. Currently, I delete the broken tests before I run the batch. I want a way to force this window to abort or ignore - so I don't need to skip the broken tests.
This problem is similar to; however, I cannot write to reg keys
How do I disable the 'Debug / Close Application' dialog on Windows Vista?
Update: My manager says this window might not appear if this project was in release. Trying to do that now. However, if there is a solution besides changing my project to release, I would appreciate it! :D
That's what you get from a failed assert() in the source code. Useful to debug the test. But actually running unit tests against code that was compiled in the Debug configuration is not useful. Your customer isn't going to run the Debug build either.
Only test the Release build, that disables those assert() calls as well.
I'm using Visual Studio 2010 SP1. When I run "All Tests in Solution", I get code coverage results to show up just fine. However, when I run a subset of tests using "Tests in Current Context", I only see "Cannot find any coverage data (.coverage or .coveragexml) files. Check test run details for possible errors."
A Google search shows that others do get code coverage results when running a subset of tests. Is there a configuration I'm missing somewhere?
I think I figured out the reason for this, but it still doesn't make complete sense. If I run the tests in the current context by going to "Test -> Debug -> Tests in Current Context", it doesn't work (code coverage is not generated). However, if I do "Test -> Run -> Tests in Current Context", then it works. So far so good, it kind of makes sense that it would only work when not in Debug mode.
But the strange part is if I use the keyboard shortcut for "Test -> Run -> Tests in Current Context" (Ctrl-R, T), it does not work. So I have to run it from the menu instead of using the keyboard shortcut, otherwise it says no code coverage was generated.
When I want to run 1 test, I always have to right-click the method declaration and click "Run Test". Is there a way to do this without using the mouse?
See if there are any relevant entries from TestDriven.NET in Tools - Options - Keyboard (for instance, ReSharper adds "ReSharper.ReSharper_UnitTest_ContextRun", which allows to run a unit test method editor cursor is currently in) and bind that to some keyboard shortcut.
If you go to Tool=> Options => Keyboard then you can create a new shortcut key to run the unit test for a method or the complete suite. Just pick up the command from the list and assign a key.
A quick google for "TestDriven.NET keyboard shortcuts" gives a few helpful pages.
http://weblogs.asp.net/nunitaddin/archive/2004/08/30/222447.aspx
http://www.lostechies.com/blogs/jimmy_bogard/archive/2008/02/27/testdriven-net-keyboard-shortcut.aspx