无法运行NUnit测试

问题描述:

我安装了NUnit 2.6.1并尝试在Windows 7 x64上运行一个简单的测试。它导致异常无法运行NUnit测试

尝试加载格式不正确的程序。您 可能会尝试加载使用CLR的更高版本的 版本构建的程序集,而不是NUnit当前运行的版本 (2.0.50727)或尝试将64位程序集加载到32位进程中。

这是很奇怪,因为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> 

这听起来并不像NUnit的一个问题。这听起来像你的单元测试程序集不是为32位处理而构建的。你确定你的单元测试程序集是为32位构建的吗?如果NUnit运行32位,并且您的程序集构建在64位(或不构建为任何CPU),则会出现此问题。调用应用程序确定程序集所需的位深度。你不能使用32位进程的64位DLL,反之亦然。

我提到这个的唯一原因是因为你的问题说你试图运行测试。如果NUnit配置不正确,甚至不会启动。

+0

不理解你。 NUnit是64位,对吧?我的系统也是64位,我需要测试的程序也是64位。问题在哪里? – Alexandre

+2

问题是你正在构建64位DLL,但在32位模式下运行NUnit。你确定你正在运行64位的NUnit吗?有一个单独的64位可执行文件。或者你是这样做的,你正在运行64位的NUnit并加载32位的DLL。无论哪种方式是不匹配的,它不高兴 – devshorts

+0

不,我不是。我如何在64模式下运行它(NUnit)? “或者你是这样做的,你正在运行64位的NUnit并加载32位的dll。”其实,我不知道。我怎么知道它? – Alexandre