Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are NUnit testing times slow when using 'Run All' in VS 2015 Test Explorer?

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.

Test Explorer using 'Run All'

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.

Test Explorer using 'Run Selected Tests'

I've have not found any clues as to why it takes so much longer to use 'Run All'.

like image 459
jared Avatar asked Nov 02 '15 22:11

jared


1 Answers

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.

like image 145
Andreas Avatar answered Nov 15 '22 08:11

Andreas