代码之家  ›  专栏  ›  技术社区  ›  harpo Binary Worrier

找不到NUnit程序集

  •  20
  • harpo Binary Worrier  · 技术社区  · 17 年前

    我以前用过NUnit,但不是很长时间,也从来没有在这台机器上用过。我在下面解压了2.4.8版 Program Files

    为了简化问题,我编译了最基本的测试文件。

    using NUnit.Framework;
    
    namespace test
    {
        [TestFixture]
        public class Tester
        {
            [Test]
            public void ATest()
            {
                Assert.IsTrue(false, "At least the test ran!");
            }
        }
    }
    

    我已将“C:\Program Files\NUnit-2.4.8-net-2.0\bin”添加到路径中(并重新启动)。请注意,如果我将测试程序集复制到该文件夹中,则

    C:\Program Files\NUnit-2.4.8-net-2.0\bin>nunit-console test.dll
    

    有效,但是

    C:\Program Files\NUnit-2.4.8-net-2.0\bin>nunit-console c:\dev\nunit_test\test.dll
    

    C:\dev\nunit_test>nunit_console test.dll
    

    由于上述错误而失败。

    bin 文件夹,但我不记得以前必须这样做。此外,我在GUI中也遇到了同样的错误。GUI不应该知道框架的位置(即,在同一个文件夹中)吗?

    我没有使用Visual Studio。我使用下面这行代码来编译测试项目。

    %windir%\Microsoft.NET\Framework\v2.0.50727\csc.exe /r:"C:\Program Files\NUnit-2.4.8-net-2.0\bin\nunit.framework.dll" /t:library /out:test.dll test.cs
    

    5 回复  |  直到 6 年前
        1
  •  12
  •   Scott Pedersen    17 年前

    确保已添加对nunit.framework的引用。如果有,请确保该引用的属性将“复制本地”属性设置为true。

        2
  •  11
  •   Peter Mortensen Pieter Jan Bonestroo    6 年前

    我也有同样的问题,我是使用NUnit-2.4.8-net-2.0.msi安装的。扩展 the "add to the GAC" comment ,以下是我所做的:

    • 从GAC注销您的NUnit条目。您可以通过查找在GAC中注册的NUnit条目来执行此操作:

      gacutil /l | find /i "nunit" > temp.bat && notepad temp.bat
      
    • 在nunit.core和nunit.framework行前面加上“gacutil/uf”,即:

      gacutil /uf nunit.core,Version=2.4.2.0,Culture=neutral,PublicKeyToken=96d09a1eb7f44a77
      
      gacutil /uf  nunit.framework,Version=2.4.2.0,Culture=neutral,PublicKeyToken=96d09a1eb7f44a77
      
    • 运行.bat文件以删除它们: temp.bat

    • 注册所需的NUnit DLL文件:

      gacutil /i nunit.core.dll
      
      gacutil /i nunit.framework.dll
      
        3
  •  10
  •   Peter Mortensen Pieter Jan Bonestroo    6 年前

    如果使用NUnit-2.4.8-net-2.0.msi安装,则NUnit程序集将添加到 GAC .

        4
  •  2
  •   Peter Mortensen Pieter Jan Bonestroo    6 年前

    请注意,当前的NUnit安装(2.5.10)不会在GAC中自动注册。

    如果您必须使用GAC,请通过 gacutil /i <nunitframeworkpath> 哪里 nunitframeworkpath %Program Files%\NUnit\net-2.0\framework\nunit-framework .

        5
  •  1
  •   Curt    15 年前

    今天,当我尝试向现有NUnit测试项目添加新的测试程序集时,收到了此错误消息。似乎我的测试项目对相同的nunit.framework.dll程序集有多个路径引用。

    如果NUnit项目中有多个测试程序集,则可能需要验证测试项目中NUnit.framework引用的路径属性。一旦我让他们匹配,错误信息就消失了。