简体   繁体   English

NUnit首先在Resharper测试运行器中使用Entity Framework测试非常慢

[英]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 ? 使用Entity Framework 4.1时,第一个NUnit测试的缓慢是否有任何解决方案?

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) 我发现第一次测试大约需要10秒钟,其余的测试都在0.01秒内完成(根据Resharper Show Time选项)

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 如果我使用NUnit GUI运行测试,那么第一次测试需要10秒,但是如果我重新运行整套测试运行时间不到0.5秒...... 直到我重新编译解决方案

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. 我还有一个在IIS中托管的WCF服务的NUnit测试,它调用EF,第一个在大约3秒内完成。 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. 然后,如果我重新运行测试,它会降低到1秒,正如预期的那样,在重新编译时,第一次会回到3秒。

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 但是最初的NUnit测试是针对具有调用EF的方法的类库,总是大约10秒标记, 即没有减少时间

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 ?? 好吧,我知道IIS正在做“某事” [什么?] ,但在这两种情况下我都在使用NUnit来进行呼叫......为什么第一次呼叫需要10秒以上,另一次是3秒然后是1秒第二次接下来的电话?

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. 为了让我感到困惑,我编写了一个简单的控制台应用程序,它可以调用正在测试的类中的一个EF使用方法,并且它可以在1秒内完成。

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 ...重写相同的测试,因为MSTest测试在大约3.5秒内完成了第一次测试,这与NUnit GUI运行器中的第一次测试运行相当,所以问题似乎是NUnit在Visual中的Resharper测试运行器工作室

UPDATE 2 ... yes, the issue does seem to be the Resharper test runner. 更新2 ...是的,问题确实似乎是Resharper测试运行器。 TestDriven.NET and Visual Nunit 2010 both are quicker. TestDriven.NET和Visual Nunit 2010都更快。

UPDATE 3 ... and it's now logged with JetBrains as an issue 更新3 ...它现在以JetBrains作为问题记录

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. 这是常见的行为,因为第一个测试必须编译“EF视图” - 这是在您第一次使用模型中映射的任何内容时发生的。 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. 它可以避免,但它需要您手动生成视图代码( 通过使用EdmGen.exe )将该代码添加到您的项目并与您的解决方案一起编译。 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). 每次在EDMX中更改任何内容时都必须执行此操作,除非您将其作为项目中的某些预构建操作(这将反过来减慢构建速度)。

The difference between the various runners may be due to the platform (x64 vs. x86) they're using. 各种跑步者之间的差异可能是由于他们正在使用的平台(x64与x86)。 EF is much slower to start in x64 mode. 在x64模式下启动EF要慢得多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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