Microsoft.Fakes won't run in normal unit test contexts

前端 未结 3 399
囚心锁ツ
囚心锁ツ 2020-12-30 23:50

I\'m using a simple proof-of-concept Fakes nUnit test:

  [Test]
  public void TestFakes()
  {
      using (var ctx = ShimsContext.Create())
      {
                  


        
相关标签:
3条回答
  • 2020-12-31 00:22

    Fakes works only with Visual Studio Test Runner(AKA VStest.Console.exe). Even previous Microsoft MSTest runner doesn't support it.

    0 讨论(0)
  • 2020-12-31 00:25

    I don't think you will be able to execute MS Fakes based tests using anything other then MS Test framework.

    I believe that the way MS Fakes works causes problems for test runners such as NUnit. Precisely why this is the case, I don't know, since other mocking frameworks such as TypeMock work fine in NUnit, etc. But there is something specific to MS Fakes which make it harder (if not impossible) to run with anything other than MS Test. That's my theory anyway.

    Unless the authors of NUnit, xUnit, etc add support for MS Fakes (or there is a crafty workaround), I think you will have to stick with MS Test.

    EDIT:

    It looks like the latest version of NCrunch v2.5 does work with MS Fakes. I've tried the beta during it's development, and can confirm that MS Fake tests were executed without fail using NCrunch.

    0 讨论(0)
  • 2020-12-31 00:41

    I believe your answer is to use one of following commands:

    VSTest.Console.exe UnitTests.dll /UseVsixExtensions
    
    VSTest.Console.exe UnitTests.dll /TestAdapterPath:%LocalAppData%\Microsoft\VisualStudio\12.0\Extensions\<nunit test adapter installation folder>
    

    These commands will run fine on dev machines. In case you want to run unit tests on build server, copy nunit test adapter folder to build server and mention that path.

    0 讨论(0)
提交回复
热议问题