简体   繁体   中英

NUnit first test very slow with Entity Framework in Resharper test runner

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

I'm finding it takes about 10 seconds for the first test, the rest of my tests are running in 0.01 seconds (according to Resharper Show Time option)

If I run the tests using the NUnit GUI, again first test takes 10 seconds, but if I re-run the entire set of tests runs in less than 0.5 second ... until I re-compile the solution

I've also got a NUnit tests of a WCF service hosted in IIS, which calls EF, and the first one finishes in about 3 seconds. Then if I re-run tests, it's down to 1 second and, as expected, on recompile the first time is back to 3 seconds.

But the original NUnit tests, which are against a class library with methods calling EF, are always around the 10 second mark, ie no decrease in time

Ok, I get that IIS is doing "something" [what?] , but in both cases I'm using NUnit to do the calls ... why is one 10+ seconds for first call, the other is 3 seconds and then 1 second on subsequent calls ??

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

UPDATE ... the same tests re-written as 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 issue seems to be the Resharper test runner for NUnit in Visual Studio

UPDATE 2 ... yes, the issue does seem to be the Resharper test runner. TestDriven.NET and Visual Nunit 2010 both are quicker.

UPDATE 3 ... and it's now logged with JetBrains as an issue

That is common behavior because the first test will have to compile "EF views" - this happens first time you use anything mapped in your model. The same compiled views are then cached and reused. It can be avoided but it requires you manually generate the code for views ( by using EdmGen.exe ) add that code to your project and compile together with your solution. You will have to do this each time you change anything in EDMX unless you make it as some pre-build action in your project (it will in turn slow your build).

The difference between the various runners may be due to the platform (x64 vs. x86) they're using. EF is much slower to start in x64 mode.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM