我的 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 二进制文件的路径。当我调用 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>
关于c# - <nunit2> 工作不正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2487386/