c#-4.0 - 如何告诉nunit-console在Mono下使用4.0?

标签 c#-4.0 mono nunit

我在 MonoDevelop 下设置了一个简单的项目,并且可以从那里成功运行测试 (*)。

当我从命令行尝试 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-console 包含以下内容:

#!/bin/sh

exec /usr/bin/cli /usr/lib/nunit/nunit-console.exe "$@"

/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 属性时遇到了问题;这是我正在尝试解决的真正问题,这导致我遇到了上面描述的问题。然而,上面使用的 exe 只需要两个简单的测试,就可以在 MonoDevelop 中正常工作。

最佳答案

诀窍是修改 nunit-console,它(在 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-console 以始终进行设置。

(真正的问题是/usr/bin/cli 自动检测选择 NET 2 而不是 NET 4;但经过大量搜索后,我发现无法控制该自动检测过程.)

<小时/>

ASIDE:我强调 /usr/bin/cli 的原因是,仅仅告诉 nunit-console 要使用的框架会失败(见下文)。 IE。运行时版本必须提供给/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 
...

关于c#-4.0 - 如何告诉nunit-console在Mono下使用4.0?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13069078/

相关文章:

C# Mono MySql 连接器 :Unable to connect to any specified MySQL hosts

.net - 如何使用 C# 获取 RAM 的完整内存转储

javascript - C# 内联 if 或值语法

C# 泛型,将泛型列表转换到已知的父类?

iphone - 在 monotouch 中处理 json 的最佳方法是什么

c# - 在 Linux 上使用 C#/Mono 处理外部媒体

c# - TestServer返回404未找到

.net - 集成测试

nunit - 如何使NUnit3TestAdapter与.Net Standard 2.0一起使用?

c# - 如何使用 C# 从时间格式大于 24 小时的字符串中获取总秒数