【问题标题】:Making VS2008 tests into NUnit tests将 VS2008 测试变成 NUnit 测试
【发布时间】:2010-11-03 08:01:12
【问题描述】:

听说 VS2008 中自动生成的测试可以通过添加来兼容 NUnit

#if !NUNIT
using Microsoft.VisualStudio.TestTools.UnitTesting;
#else
  using NUnit.Framework;
  using TestClass = NUnit.Framework.TestFixtureAttribute;
  using TestMethod = NUnit.Framework.TestAttribute;
  using TestInitialize = NUnit.Framework.SetUpAttribute;
  using TestCleanup = NUnit.Framework.TearDownAttribute;
  using TestContext = System.String;
  using DeploymentItem = NUnit.Framework.DescriptionAttribute;
#endif

编辑:自从我修复了参考问题后,这个问题的焦点略有改变。再一次,有人告诉我这个语句可以更改为正确的单元测试程序,VS 或 NUnit。

它永远不会进入 else 语句。所以新的问题是,我是否需要将条件更改为其他内容,还是我又错过了一些简单的内容?

【问题讨论】:

    标签: visual-studio-2008 unit-testing nunit


    【解决方案1】:

    您是否引用了 NUnit 程序集来代替 VS 测试程序集?

    【讨论】:

      【解决方案2】:

      您是要转换测试还是在同一个项目中同时运行 NUnit 和 VS 测试?如果您正在转换,那么您应该能够使用查找和替换来进行大部分更改。

      我进行了从 VS 测试到 NUnit 的转换,发现了一个语法差异:IsInstanceOfType 方法的参数顺序不同。

      【讨论】:

        【解决方案3】:

        好吧,在我忽略了 Richard 向我指出的一个简单错误之后,我发现了该怎么做。

        因为我在 CC.NET 中运行这些,所以我只是为变量采取了简单的方法并在 cmd 中设置了一个 windows 变量,然后使用 nunit-console.exe 运行 dll。

        如果您真的不关心能否在 VS2008 和 NUnit 测试程序之间来回交换,您可以只取出预编译代码,将 if 的内容留给 VS,将 else 的内容留给 NUnit。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2014-07-19
          • 1970-01-01
          • 2020-09-06
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-04-01
          相关资源
          最近更新 更多