4

nunit2 タスクを使用してテストを実行しようとすると、このエラーが発生します

テストの実行に失敗しました。アセンブリが NUnit バージョン 2.6.0.12051 を使用してビルドされていない場合は、アセンブリ バインディングがリダイレクトされていることを確認してください。

テスト プロジェクトの nunit バージョンは 2.6.2.12296 です。

テスト プロジェクトの構成ファイルでいくつかのリダイレクト バインディングをテストしましたが、うまくいきませんでした。nunit2 タスクを使用する代わりに nunit.exe を直接実行できることはわかってEXECいますが、これを機能させたいと思います。

アップデート

これは、テスト プロジェクトの現在の app.config です。

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
    </dependentAssembly>
    </assemblyBinding>

    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
          <assemblyIdentity name="nunit.framework" publicKeyToken="96d0234a77" culture="Neutral" />
          <bindingRedirect oldVersion="0.0.0.0-2.6.0.12051" newVersion="2.6.2.12296" />
        </dependentAssembly>
    </assemblyBinding>

  </runtime>
</configuration>

更新 2

これはビルドファイルの関連部分です

<nunit2>
  <test 
    assemblyname="D:\[the full path]\UnitTests.dll" 
    appconfig="D:\customTest.config"/>
  <formatter type="Plain"/>
</nunit2>
4

3 に答える 3

3

テスト フレームワークのバージョンが NAnt のビルドに使用したバージョンと一致しない場合に NAnt NUnit2 タスクを使用する場合、バインディング リダイレクトを使用するように NAnt NUnit2 タスクに指示する必要があります。

問題は、NUnit テスト ランナーがテストごとに新しい AppDomain を作成するため、テスト プロジェクトの app.config でバインディング リダイレクトを実行できないことです。

バインディング リダイレクトを使用してカスタム構成ファイルを作成する必要があります。

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="nunit.framework" publicKeyToken="96d0234a77" culture="Neutral" />
      <bindingRedirect oldVersion="0.0.0.0-2.6.2.12051" newVersion="2.6.2.12296" />
    </dependentAssembly>
  </assemblyBinding>
</runtime> 

NUnit2 NAnt タスクにそれを使用するように指示します。

<nunit2>
    <test assemblyname="ProjectName.Tests.dll" appconfig="customTest.config" />
     ...
</nunit2>

--------------最後の考え------------------------------

あなたの設定は次のとおりです。

<bindingRedirect oldVersion="0.0.0.0-2.6.0.12051" newVersion="2.6.2.12296" />

試してみてください

<bindingRedirect oldVersion="0.0.0.0-2.6.2.12296" newVersion="2.6.2.12296" />

テストプロジェクトのすべての外部参照がcopy local=trueVisualStudioのプロパティウィンドウにあるかどうかを再確認してください

于 2013-11-13T17:46:48.973 に答える
2

NUnit のドキュメント<bindingRedirect> で説明されているように、.config に追加します。

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="nunit.framework" publicKeyToken="96d0234a77" culture="Neutral" />
      <bindingRedirect oldVersion="0.0.0.0-2.6.2.12051" newVersion="2.6.2.12296" />
    </dependentAssembly>
  </assemblyBinding>
</runtime> 

または、Nant<exec>を次のように使用します。

 <exec program="${LibraryPath}\NUnit\2.6.2\nunit-console.exe">
   <arg value="${SourcePath}\ProjectName.Tests\bin\Release\ProjectName.Tests.dll" />
 </exec>
于 2013-11-08T12:39:23.520 に答える