NUnit's first test is very slow with Entity Framework in Resharper tester

Is there any solution to the slowness of the first NUnit test when using Entity Framework 4.1?

I find that the first test takes about 10 seconds, the rest of my tests run after 0.01 seconds (according to the Resharper Show Time parameter)

If I run tests using the NUnit GUI, again the first test takes 10 seconds, but if I re-run the entire test suite, skipping in less than 0.5 seconds ... until I recompile the solution

I also have NUnit tests of a WCF service hosted in IIS that calls EF, and the first ends after about 3 seconds. Then, if I re-run the tests, it will drop to 1 second and, as expected, recompiling for the first time will return for 3 seconds.

But the original NUnit tests, which refer to the class library with methods that call EF, are always around 10 seconds, i.e. without reducing the time

Ok, I realized that IIS does โ€œsomethingโ€ [what?], But in both cases I use NUnit to make calls ... why for the first call is 10 + seconds, the other is 3 seconds and then 1 second on subsequent challenges

And to really confuse me, I wrote a simple console application that calls one of the EF using methods in the tested class, and it manages to complete in 1 second.

UPDATE ... the same tests that were overwritten since the MSTest tests finish the first test in about 3.5 seconds, which is comparable to the first test run in the NUnit GUI runner, so the problem seems to be Resharper test runner for NUnit in Visual Studio

UPDATE 2 ... yes, the problem seems to be the Resharper test runner. TestDriven.NET and Visual Nunit 2010 are faster.

UPDATE 3 ... and now it is registered by JetBrains as a problem

+7
source share
2 answers

This is normal behavior because the first test will have to compile โ€œEF viewsโ€ โ€”this is the first time you use anything displayed in your model. The compiled views are then cached and reused. It can be avoided, but this requires that you manually generate the code for the views ( using EdmGen.exe ) add this code to your project and compile it with your solution. You will need to do this every time you change something in EDMX, unless you do it as some preliminary action in your project (this, in turn, will slow down your build).

+2
source

The difference between the different players may be related to the platform (x64 versus x86) that they use. EF is much slower to run in x64 mode.

+1
source

All Articles