【问题标题】:<nunit2> is not working correctly<nunit2> 工作不正常
【发布时间】:2010-03-21 14:21:46
【问题描述】:

我的 nant 脚本中有以下任务:

<nunit2 verbose="true">
            <formatter type="Plain" />
            <test assemblyname="${output}\Test.dll" appconfig="${project.src.root}\Test\Test.config"/>
</nunit2>

Test.config 如下:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="nunit.framework" publicKeyToken="96d09a1eb7f44a77" culture="Neutral" />
        <bindingRedirect oldVersion="2.5.3.9345" newVersion="2.2.8.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

运行此任务时出现错误,提示无法加载 nunit.framework。我知道 nunit 不在 GAC 中(没有强签名)。 Nunit 是否必须加入 GAC 才能执行此任务?

【问题讨论】:

  • NUnit 不一定要在 GAC 中才能工作。

标签: c# nant


【解决方案1】:

我在编译期间提供了 NUnit 二进制文件的路径。当我调用 nunit2 时,存在对框架的引用并且我没有收到此错误。这有帮助吗?

<target name="unit.compile" depends="sharedClasses, helpers.compile" description="compiles the unit tests" >
    <copy todir="build" flatten="true">
        <fileset basedir="tools\NUnit-2.5.2.9222\framework">
            <include name="nunit.framework.dll" />
        </fileset>
    </copy>

    <csc target="library" output="build\${project::get-name()}.test.unit.dll" debug="${debug}">
        <sources>
            <include name="source\web\tests\unit\**\*.cs" />
            <exclude name="source\web\tests\unit\**\AssemblyInfo.cs" />
        </sources>

        <references basedir="build" >
            <include name="nunit.framework.dll" />
            <include name="Microsoft.Practices.EnterpriseLibrary.Common.dll" />
            <include name="Microsoft.Practices.EnterpriseLibrary.Data.dll" />
            <include name="${project::get-name()}.sharedClasses.dll" />
            <include name="${project::get-name()}.test.helpers.dll" />
        </references>
    </csc>
</target>
<target name="unit.test" depends="unit.compile, helpers.compile">
    <copy file="configuration\Web.Config"       tofile="build\${project::get-name()}.test.unit.dll.config" />
    <copy file="configuration\ui_list.config"   tofile="build\ui_list.test.config" />

    <nunit2>
        <test
            assemblyname="build\${project::get-name()}.test.unit.dll" 
               appconfig="build\${project::get-name()}.test.unit.dll.config"
        />
        <formatter type="Plain" />
    </nunit2>
</target>

【讨论】:

    【解决方案2】:

    将您的 Nant 任务设置为显示详细输出(通常这意味着只需将 'verbose=true' 添加到适用的任务中)并查看您是否可以验证它试图用于引用 nunit.framework.dll 的路径。

    您的项目中 nunit.framework.dll 的路径很可能是一个相对路径,当您尝试通过命令行从 NAnt 运行任务时可能无法正常工作。 (例如,如果您的 .csproj 嵌套在一个文件夹中,但您的 Nant 脚本没有,或者如果您在测试之前移动构建输出)。

    【讨论】:

      猜你喜欢
      • 2020-04-23
      • 2023-04-10
      • 2015-01-16
      • 1970-01-01
      • 2016-08-02
      • 2020-02-18
      • 2013-01-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多