Peter Morris
Peter Morris

Reputation: 23224

MSTests run in Visual Studio, but not via dotnet test

https://github.com/mrpmorris/AutoRegister (deleted-tests branch)

My unit tests project has a project reference to Morris.AutoRegister.Fody. When I run the tests in Visual Studio they work fine, but when I run them via dotnet test in the Source folder I get the following error for every test...

C:\Data\Mine\Code\AutoRegister\Source\Lib\Morris.AutoRegisterTests\ModuleWeaverTests\AutoRegisterAttributeTests\FindTests\ServiceTypeFilterTests.cs(31): error test failed:
      WhenAServiceTypeFilterIsSpecified_ThenOnlyServiceTypesMatchingThatFilterAreRegistered (1ms): Test method Morris.Au
      toRegisterTests.ModuleWeaverTests.AutoRegisterAttributeTests.FindTests.ServiceTypeFilterTests.WhenAServiceTypeFilt
      erIsSpecified_ThenOnlyServiceTypesMatchingThatFilterAreRegistered threw exception:
      System.IO.FileNotFoundException: Could not load file or assembly 'Morris.AutoRegister.Fody, Version=1.0.0.0, Cultu
      re=neutral, PublicKeyToken=null'. The system cannot find the file specified.
      Stack Trace:
          at Morris.AutoRegisterTests.ModuleWeaverTests.WeaverExecutor.Execute(String sourceCode, TestResult& testResult
      , String& manifest, Boolean assertNoDiagnosticsOutput, String partialMethodsSourceCode)
         at Morris.AutoRegisterTests.ModuleWeaverTests.AutoRegisterAttributeTests.FindTests.ServiceTypeFilterTests.WhenA
      ServiceTypeFilterIsSpecified_ThenOnlyServiceTypesMatchingThatFilterAreRegistered() in C:\Data\Mine\Code\AutoRegist
      er\Source\Lib\Morris.AutoRegisterTests\ModuleWeaverTests\AutoRegisterAttributeTests\FindTests\ServiceTypeFilterTes
      ts.cs:line 31
         at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructo
      r)
         at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

UPDATE

  1. If I build the app in VS and then execute dotnet test --no-build then the test runs and passes.
  2. If I execute dotnet test --no-restore then it rebuilds and still works.
  3. If I execute dotnet test it restores + rebuilds and then fails.
  4. I spotted the following diff in Morris.AutoRegisterTests.deps.json

File diff

Upvotes: 2

Views: 53

Answers (0)

Related Questions