简体   繁体   English

无法运行NUnit测试

[英]Unable to run NUnit test

I installed NUnit 2.6.1 and trying to run a simple test on Windows 7 x64. 我安装了NUnit 2.6.1并试图在Windows 7 x64上运行一个简单的测试。 It causes an exception 它会导致异常

An attempt was made to load a program with an incorrect format. 尝试加载格式不正确的程序。 You may be attempting to load an assembly built with a later version of the CLR than the version under which NUnit is currently running (2.0.50727) or trying to load a 64-bit assembly into a 32-bit process. 您可能正在尝试加载使用CLR的更高版本构建的程序集,而不是NUnit当前运行的版本(2.0.50727)或尝试将64位程序集加载到32位进程中。

It is pretty weird because nunit.exe.config looks like below 这很奇怪,因为nunit.exe.config如下所示

  <?xml version="1.0" encoding="utf-8" ?> 
- <configuration>
- <!-- 
   The GUI only runs under .NET 2.0 or higher. The
   useLegacyV2RuntimeActivationPolicy setting only
   applies under .NET 4.0 and permits use of mixed 
   mode assemblies, which would otherwise not load 
   correctly.


  --> 
- <startup useLegacyV2RuntimeActivationPolicy="true">
- <!--  Comment out the next line to force use of .NET 4.0 
  --> 
- <!--  <supportedRuntime version="v2.0.50727" /> 
  --> 
  <supportedRuntime version="v4.0.30319" /> 
  </startup>
- <runtime>
- <!--  Ensure that test exceptions don't crash NUnit 
  --> 
  <legacyUnhandledExceptionPolicy enabled="1" /> 
- <!--  Run partial trust V2 assemblies in full trust under .NET 4.0 
  --> 
  <loadFromRemoteSources enabled="true" /> 
- <!--  Look for addins in the addins directory for now 
  --> 
- <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  <probing privatePath="lib;addins" /> 
  </assemblyBinding>
  </runtime>
  </configuration>

This doesn't sound like a problem with NUnit. 这听起来不像NUnit的问题。 This sounds like your unit test assemblies are not built for a 32 bit process. 这听起来像您的单元测试程序集不是为32位进程构建的。 Are you sure your unit test assemblies are built for 32 bit? 您确定您的单元测试组件是否为32位构建? If NUnit is running 32 bit and your assemblies are built at 64 bit (or not built as Any CPU) you'll get this problem. 如果NUnit运行32位并且您的程序集是以64位(或不构建为任何CPU)构建的,那么您将遇到此问题。 The calling application determines the bit depth required of the assembly. 调用应用程序确定程序集所需的位深度。 You can't use 64 bit dll's with a 32 bit process and vice versa. 您不能在32位进程中使用64位dll,反之亦然。

The only reason I mention this is because your question says you are trying to RUN the test. 我提到这个的唯一原因是因为你的问题说你正试图运行测试。 If NUnit was configured incorrectly it wouldn't even start. 如果NUnit配置不正确,它甚至都不会启动。

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

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