NUnit 单元测试顺序或在 TeamCity 中单独运行

NUnit unit tests order or separate runner in TeamCity

问题:

我可以为构建中的单元测试子组使用单独的单元测试运行器吗?所有需要单独运行程序的程序都包含在单个 .dll

或者至少可以指定单元测试的顺序?

背景:

我有一些单元测试正在测试与使进程内存变脏的本机组件的集成,因此在生产代码中我在使用它们后回收我的进程。 (它是针对 .net 的 python 集成,有些包不是为 python 引擎卸载和重新加载而设计的)。 然而,单元测试仅由应用程序域隔离 - 因此它们仍然保留在同一进程中并且可能发生冲突。

您可以使用 [TestCategory] ​​NUnit 属性创建不同的测试组。分组后,您可以 运行 仅来自 TeamCity 服务器的特定组。你也可以把它分成不同的步骤。

但作为变体,您也可以使用 [OneTimeSetUp] 和 [OneTimeTearDown] 属性。

有用的链接:

  1. https://msdn.microsoft.com/en-us/library/dd286683.aspx - TestCategory 属性的说明。
  2. http://nunit.org/docs/2.5/consoleCommandLine.html - 如何 运行 您的测试类别来自 nunit-console。
  3. https://confluence.jetbrains.com/display/TCD9/Getting+Started+with+NUnit#GettingStartedwithNUnit-Case1.CommandLine - 如何在团队城市中使用 nunit-console。

第二种方法:

  1. https://github.com/nunit/docs/wiki/OneTimeSetUp-Attribute
  2. https://github.com/nunit/docs/wiki/OneTimeTearDown-Attribute

原来 TeamCity 支持通过单独的测试运行程序进程分离测试程序集 - 在 NUnit 构建步骤配置中称为 'Run process per assembly' 的选项:

此处有更多详细信息:https://confluence.jetbrains.com/display/TCD10/NUnit(搜索 'Run process per assembly')