Microsoft Fakes generates UnitTestIsolationException

眉间皱痕 提交于 2019-12-10 13:26:19

问题


I have written very simple unit test project to see abilities of Microsoft Fakes. And I have executed on System assembly the menu command "Add Fakes Assembly".

public static class Y2KChecker
{
    public static void Check()
    {
        if (DateTime.Now == new DateTime(2000, 1, 1))
            throw new ApplicationException("y2kbug!");
    }
}

[TestClass]
public class UnitTest1
{
    [TestMethod]
    public void TestYear()
    {
        using (ShimsContext.Create())
        {
            ShimDateTime.NowGet = () => new DateTime(2000, 1, 1);
            Y2KChecker.Check();
        }
    }
}

But in line using (ShimContext.Create()) I get always the UnitTestIsolationException:

Unexpected error returned by SetDetourProvider in profiler library 'C:\Program Files\Microsoft Visual Studio 11.0\Common7\IDE\CommonExtensions\Microsoft\IntelliTrace\11.0.0\Microsoft.IntelliTrace.Profiler.11.0.0.dll'.

With my Visual Studio 2012 Update 2 is also installed Resharper. How fix this exception?


回答1:


As of November 2012 you cannot run Resharper and MS Fakes at the same time. A request to make it compatible was put in almost a year ago.

http://devnet.jetbrains.com/message/5470396?tstart=0




回答2:


By now (March 2014) you can run tests that uses MS Fakes only in Visual Studio Test Runner (vstest.console.exe). Of course you can continue to use ReSharper, but its test runners can't be able to run your tests.




回答3:


I have the same issue when working with VS2012 + ReSharper, I switched to VS2013 without ReSharper and it worked just fine.

I went back to VS2012 and tried to suspend ReSharper but that didn't solve the issue.




回答4:


In my case, the problem happend only at TeamCity.

I solved by switching from MSTest to VSTest.




回答5:


As of October 2017 I was able to run the tests through Resharper but not when gathering code coverage



来源:https://stackoverflow.com/questions/20686805/microsoft-fakes-generates-unittestisolationexception

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!