I am using Test Explorer in Visual Studio 2015 via the NUnit VS Adapter to run my unit tests.
When using Test Explorer's 'Run All' command my tests run and show pass/fail within a second, yet the total runtime is 34 seconds.
When selecting all of the tests and using 'run selected tests' from the right-click context menu the same tests take a total runtime of 1 second.
I've have not found any clues as to why it takes so much longer to use 'Run All'.
Let's look at the output window. If I take "Run all" the output window looks like this
------ Discover test started ------
========== Discover test finished: 92 found (0:00:00.4993709) ==========
------ Run test started ------
========== Run test finished: 92 run (0:00:04.157636) ==========
If I instead select all tests I want to test the output window looks like this
------ Run test started ------
========== Run test finished: 92 run (0:00:03.7262618) ==========
The point is that when you take "Run all" the Test explorer has to go through all code and re-find all classes with the "TestClass" attribute and all its methods decorated with the "TestMethod" attribute (this is done via reflection which in some cases might be a bit "slow"). Why? So that the test explorer can find all new and exisiting test methods.
When you manually select the methods you want to test, the test explorer doesn't have to re-find all existing and new methods to test, hence it is faster.
This is a bit of a guess of what the "Total run time" means, I've never used NUnit and theese thoughts was to long to post in a comment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With