【问题标题】:How to use a common test harness for MStests & NUnit and run them in Mono?如何为 MStests 和 NUnit 使用通用测试工具并在 Mono 中运行它们?
【发布时间】:2011-09-22 18:53:18
【问题描述】:

我正在使用 VS2010 开发一个项目,并将在现有的充满 MStests 的测试工具中添加一些 NUnit 测试。如何在 Mono 中只运行该工具的 NUnit 测试?当我在 PC 和 Mac 上运行 MSTests 和 NUnit 测试时,我有选择地在它们之间切换吗?或者仅使用 NUnit 测试制作单独的测试工具并以单声道运行它们是唯一的解决方案?我试图找到更简单的方法,但似乎没有多少人尝试过。任何指针表示赞赏!

【问题讨论】:

  • 在所有测试中使用 NUnit 有什么问题?转换它们的时间和精力?
  • 是的,大约有 700 个测试,其中大部分由不想将它们转换为 NUnit 的合作伙伴团队拥有。因此,它最终必须同时支持 Win 和 Mac 平台。

标签: macos visual-studio-2010 mono nunit


【解决方案1】:

您可以尝试一个巧妙的技巧,根据目标平台将您的单元测试“交叉编译”到两个框架之一。将此作为测试文件的开头:

#if MSTEST
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Category = Microsoft.VisualStudio.TestTools.UnitTesting.DescriptionAttribute;
#else
using NUnit.Framework;
using TestInitialize = NUnit.Framework.SetUpAttribute;
using TestContext = System.Object;
using TestProperty = NUnit.Framework.PropertyAttribute;
using TestClass = NUnit.Framework.TestFixtureAttribute;
using TestMethod = NUnit.Framework.TestAttribute;
using TestCleanup = NUnit.Framework.TearDownAttribute;
#endif

(取自http://completedevelopment.blogspot.com/2009/05/blog-post.html)

【讨论】:

  • @skolima- 感谢您的建议,是否可以在 Mono 上运行这些测试?我想知道的是,像这样具有 NUnit + MStests 的测试工具如何在 Mono 上运行?使用该指令,当我将测试部署到 Mono 时,MSTests 会自动被忽略吗?
  • 它们将作为 NUnit 测试运行。
  • 谢谢……我必须要有 monodevelop 才能在 Mono 上获得 NUnit 吗?有没有办法我可以在 Mono 上独立获取 NUnit,并使用我的 testframework.dll,通过 nunit 控制台运行它?
  • 我问过同样的问题,看起来这就是解决方案 -> stackoverflow.com/questions/7562596/…,我决定创建一个由纯 NUnit 测试组成的新测试工具。添加交叉编译技巧似乎不可行,因为它需要修改大约 700 个测试来进行一些 NUnit 测试。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-07-01
  • 2013-11-05
相关资源
最近更新 更多