由于缺少程序集,单元测试未 运行

Unittests not running because of missing assembly

我已经创建了一个单元测试,但是当我尝试 运行 我在 JetBrains Rider 中收到以下错误消息。 我已经尝试了一个干净的解决方案和重建但无济于事。 有问题的项目没有引用提到的程序集。

Test not run

Last runner error: TestRunner: NUnitTestReporter Could not load file or assembly 'nunit.framework, Version=3.12.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

--- EXCEPTION #1/1 [LoggerException]
Message = “TestRunner: NUnitTestReporter Could not load file or assembly 'nunit.framework, Version=3.12.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)”
ExceptionPath = Root
ClassName = JetBrains.Util.LoggerException
HResult = COR_E_APPLICATION=80131600
StackTraceString = “
  at JetBrains.Util.ILoggerEx.LogMessage(ILogger this, LoggingLevel level, String message)
     at JetBrains.ReSharper.UnitTestFramework.TestRunner.ServerEndpoint.<>c__DisplayClass9_2.<TryRegisterHandler>b__3()
     at System.Threading.Tasks.Task`1.InnerInvoke()
     at System.Threading.Tasks.Task.Execute()
     at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
     at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
     at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot)
     at System.Threading.Tasks.Task.ExecuteEntry(Boolean bPreventDoubleExecution)
     at System.Threading.ThreadPoolWorkQueue.Dispatch()
”

执行此步骤的步骤:

  1. 使用包管理器添加 nunit。
  2. 验证 nunit 在单元测试项目的引用中
  3. 添加相关的binding redirect

这是一个示例,您可能需要稍微更改一下。

<dependentAssembly>
  <assemblyIdentity name="nunit.framework"
    publicKeyToken="2638cd05610744eb"
    culture="en-us" />
  <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="3.12.0.0" />
</dependentAssembly>

您可以找到更多帮助HRESULT: 0x80131040: The located assembly's manifest definition does not match the assembly reference