2012-10-25 64 views
3

我在MonoDevelop下设置了一个简单的项目,并且可以从那里成功运行测试(*)。如何告诉nunit控制台在Mono下使用4.0?

当我尝试从命令行的NUnit-console.exe我得到这个:

.../mono2/bin/Debug$ nunit-console mono2.exe 
NUnit version 2.5.10.0 
... 
Runtime Environment - 
    OS Version: Unix 2.6.32.44 
    CLR Version: 2.0.50727.1433 (2.10.8.1 (Debian 2.10.8.1-1~dhx1~lucid1)) 

ProcessModel: Default DomainUsage: Single 
Execution Runtime: Default 
Unhandled Exception: 
System.ArgumentException: NUnit components for version 4.0.30319 of the CLR are not installed 
... 

如果我省略掉一些重要的事情,请让我知道。

nunit-gui给出了同样的错误。 nunit-gui有一个选项,可以从2.0切换到4.0,但是当我尝试它时,再次给了我同样的错误,所以不让我改变它。

更多详细信息:Ubuntu 10.04,使用http://badgerports.org/lucid.html存储库,所以Mono 2.10.8.1。

根据MonoDevelop中的项目选项,项目设置为使用“Mono/.NET 4.0”。

更多信息:

在/ usr/bin中/ NUnit控制台包含此:

#!/bin/sh 

exec /usr/bin/cli /usr/lib/nunit/nunit-console.exe "[email protected]" 

而且在/ usr/lib中/ NUnit的/目录包含:

3073 2011-03-14 18:13 nunit.exe.config 
    2598 2011-03-14 18:13 nunit-console.exe.config 
    23040 2012-02-29 10:19 nunit-console-runner.dll 
    4608 2012-02-29 10:19 nunit-console.exe* 
    76288 2012-02-29 10:19 nunit.uiexception.dll 
259072 2012-02-29 10:19 nunit.uikit.dll 
183808 2012-02-29 10:19 nunit-gui-runner.dll 
    4096 2012-02-29 10:19 nunit.exe* 

和nunit-console.exe.config包含:

<?xml version="1.0" encoding="utf-8"?> 
<configuration> 

    <runtime> 
    <!-- We need this so test exceptions don't crash NUnit --> 
    <legacyUnhandledExceptionPolicy enabled="1" /> 

    <!-- Look for addins in the addins directory for now --> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> 
     <probing privatePath="lib;addins"/> 
    </assemblyBinding> 

    <!-- 
    The following <assemblyBinding> section allows running nunit under 
    .NET 1.0 by redirecting assemblies. The appliesTo attribute 
    causes the section to be ignored except under .NET 1.0 
    on a machine with only the .NET version 1.0 runtime installed. 
    If application and its tests were built for .NET 1.1 you will 
    also need to redirect system assemblies in the test config file, 
    which controls loading of the tests. 
    --> 
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1" 
      appliesTo="v1.0.3705"> 

     <dependentAssembly> 
     <assemblyIdentity name="System" 
          publicKeyToken="b77a5c561934e089" 
          culture="neutral"/> 
     <bindingRedirect oldVersion="1.0.5000.0" 
          newVersion="1.0.3300.0"/> 
     </dependentAssembly> 

     <dependentAssembly> 
     <assemblyIdentity name="System.Data" 
          publicKeyToken="b77a5c561934e089" 
          culture="neutral"/> 
     <bindingRedirect oldVersion="1.0.5000.0" 
          newVersion="1.0.3300.0"/> 
     </dependentAssembly> 

     <dependentAssembly> 
     <assemblyIdentity name="System.Drawing" 
          publicKeyToken="b03f5f7f11d50a3a" 
          culture="neutral"/> 
     <bindingRedirect oldVersion="1.0.5000.0" 
          newVersion="1.0.3300.0"/> 
     </dependentAssembly> 

     <dependentAssembly> 
     <assemblyIdentity name="System.Windows.Forms" 
          publicKeyToken="b77a5c561934e089" 
          culture="neutral"/> 
     <bindingRedirect oldVersion="1.0.5000.0" 
          newVersion="1.0.3300.0"/> 
     </dependentAssembly> 

     <dependentAssembly> 
     <assemblyIdentity name="System.Xml" 
          publicKeyToken="b77a5c561934e089" 
          culture="neutral"/> 
     <bindingRedirect oldVersion="1.0.5000.0" 
          newVersion="1.0.3300.0"/> 
     </dependentAssembly> 

    </assemblyBinding> 

    </runtime> 

</configuration> 

*:好的,当我尝试使用更具异国情调的Nunit属性时遇到问题;那就是real问题我正在尝试排查哪些问题导致我遇到上述问题。然而,上面使用的exe只有两个在MonoDevelop中可以正常工作的简单测试。

回答

5

关键是要修改NUnit控制台,它(在Ubuntu 10.04,使用badgerports,貌似/usr/bin/cli /usr/lib/nunit/nunit-console.exe),告诉的/ usr/bin中/ CLI使用.NET 4!

所以,当我做这个命令:

/usr/bin/cli --runtime=v4.0 /usr/lib/nunit/nunit-console.exe mytest.exe 

我得到这样的输出:

NUnit version 2.5.10.0 
... 
Runtime Environment - 
    OS Version: Unix 2.6.32.44 
    CLR Version: 4.0.30319.1 (2.10.8.1 (Debian 2.10.8.1-1~dhx1~lucid1)) 

ProcessModel: Default DomainUsage: Single 
Execution Runtime: Default 
.. 
Tests run: 2, Errors: 0, Failures: 0, Inconclusive: 0, Time: 0.040103 seconds 
    Not run: 0, Invalid: 0, Ignored: 0, Skipped: 0 

如果你只曾打算使用.NET 4,你可以编辑的/ usr/bin中/ nunit控制台始终设置此。

(该真正问题是/ usr/bin中/ CLI自动检测,而不是.NET 4选择NET 2;但经过一番搜索,我发现没有办法来控制自动检测过程)


ASIDE:我强调在/ usr/bin中/ CLI究其原因,在于只是告诉NUnit控制台框架使用失败(见下文)。即运行时版本必须提供给/ usr/bin/cli,而不是nunit-console!

/usr/bin/cli /usr/lib/nunit/nunit-console.exe -framework=v4.0 mytest.exe 
NUnit version 2.5.10.0 
... 
Runtime Environment - 
    OS Version: Unix 2.6.32.44 
    CLR Version: 2.0.50727.1433 (2.10.8.1 (Debian 2.10.8.1-1~dhx1~lucid1)) 

ProcessModel: Default DomainUsage: Single 
Execution Runtime: v4.0 
Unhandled Exception: 
System.ArgumentException: NUnit components for version 4.0 of the CLR are not installed 
Parameter name: targetRuntime 
    at NUnit.Util.TestAgency.LaunchAgentProcess (NUnit.Core.RuntimeFramework targetRuntime, Boolean enableDebug) [0x00000] in <filename unknown>:0 
... 
4

使用nunit-console4而不是nunit-console。

+1

感谢Rolf,但是没有那个名字的文件。 (我刚刚更新了我的问题,以显示它的含义。) –

+0

看起来在Ubuntu上,nunit的打包方式有点不同。你有/usr/lib/mono/4.0/nunit-console.exe吗? –

+0

不知道那么,这似乎是因为Ubuntu包NUnit:| –

相关问题