将 VS2008 测试变成 NUnit 测试

发布于 2024-07-24 21:57:29 字数 639 浏览 2 评论 0原文

我被告知,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 语句。 所以新的问题是,我是否需要将条件更改为其他内容,或者我是否再次错过了一些简单的东西?

I have been told that the automatically generated tests in VS2008 can be made compatible with NUnit just by adding

#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

EDIT: The question slightly changed focus since i fixed the reference issue. Again, I was told this statement would work to change to the correct unit test program, VS or NUnit.

It never goes into the else statement. So the new question is, do i need to change the conditional to something else, or am I missing something simple again?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

逆光飞翔i 2024-07-31 21:57:29

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

Have you referenced the NUnit assembly in place of the VS testing assembly?

那请放手 2024-07-31 21:57:29

您是否正在尝试转换测试或在同一项目中运行 NUnit 和 VS 测试? 如果您要进行转换,那么您应该能够使用 find & 替换以进行大部分更改。

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

Are you trying to convert your tests or run both NUnit and VS tests in the same project? If you're converting then you should be able to use find & replace to make most of the changes.

I went through a conversion from VS tests to NUnit and found one syntax difference: The argument order is different for the IsInstanceOfType method.

蓦然回首 2024-07-31 21:57:29

好吧,在我忽略了理查德向我指出的简单错误后,我找到了该怎么做。

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

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

Well I found out what to do after I overlooked the simple mistake Richard pointed out to me.

Since I am running these in CC.NET I just took the easy way out for the variable and set a windows variable in cmd and then ran the dll with nunit-console.exe.

If you don't really care about being able to swap back and forth between VS2008 and NUnit testings programs you can just take out the precompile code, leaving the contents of the if for VS and the contents of else for NUnit.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文