Reputation: 3924
I have a very long delay (about 1 minute! even more) when running unit test in VS2015. When running even a single test, I see the progress bar in the top of the "Test Explorer", it flows for about a minute, and then I get the test result. The reported test runtime is as expected - very small, few milliseconds.
My question is - how can I debug this? How can I see what is going on in this minute before the test actually starts to run?
Upvotes: 20
Views: 5987
Reputation: 10859
A minute is quite a long time for nothing to be happening. There is a lot of startup processing that has to happen before any tests are run (all of the assemblies and their dependencies need to be loaded for example). This hit is generally the same if you're running a single test or running all of the tests in your suite.
If you look in the "Tests" output window, you'll get a better idea of what's actually going on and the actual amount of time taken to run the tests. For example on mine, running one test shows a similar overhead to running 49 tests..
========== Run test finished: 1 run (0:00:01.0416253) ==========
========== Run test finished: 49 run (0:00:01.9156121) ==========
There are various things that can slow down assembly loading, such as static constructors. I would tend to start off by creating a fresh test project with no dependencies to verify that it doesn't exhibit the same long delay issue so that you know it's not just your machine. Then I'd add in the dependencies of your existing test project, one dependency at a time to see if adding a particular dependency triggers the delay... Then I would look at that project to see if there's anything going on, such as static constructors that attempt to connect to a database / establish network connections.
It may also be worth trying to debug your tests, but making sure that you've got Break When Exceptions are thrown turned on (if it is something like a failed database connection that's causing the slow down there's a good chance an exception might be thrown as part of that process).
Upvotes: 4