简体   繁体   English

NUnit单元测试订单或TeamCity中的单独运行器

[英]NUnit unit tests order or separate runner in TeamCity

Question: 题:

Can I use separate unit test runner for subgroup of unit tests in my build? 我可以在构建中为单元测试的子组使用单独的单元测试运行器吗? All of those that would need separate runner process are contained within single .dll 所有需要单独运行程序的程序都包含在单个.dll中

Or at least is it possible to specify order of unit tests? 或者至少可以指定单元测试的顺序?

Background: 背景:

I have some unit tests that are testing integration with native components that makes the process memory dirty and so in production code I recycle my process after using them. 我有一些单元测试正在测试与本机组件的集成,这些集成会使进程内存变脏,因此在生产代码中,我在使用它们后回收了进程。 (it's python integration for .net and some packages are not designed for python engine unload and reload). (这是.net的python集成,并且某些软件包不是为python引擎卸载和重新加载而设计的)。 However the unit tests are only isolated by app domains - so they still remain in same process and can colide. 但是,单元测试仅由应用程序域隔离-因此它们仍然保持相同的过程并且可以相互冲突。

You can use [TestCategory] NUnit attribute to create different test group. 您可以使用[TestCategory] ​​NUnit属性创建不同的测试组。 After grouping, you could run only specific group from TeamCity server. 分组后,您只能从TeamCity服务器运行特定的组。 You could also divide it into different steps. 您也可以将其分为不同的步骤。

But also as a variant, you could use [OneTimeSetUp] and [OneTimeTearDown] attributes. 但也可以使用[OneTimeSetUp]和[OneTimeTearDown]属性作为变体。

Useful links: 有用的链接:

  1. https://msdn.microsoft.com/en-us/library/dd286683.aspx - description for TestCategory attribute. https://msdn.microsoft.com/zh-cn/library/dd286683.aspx-TestCategory属性的描述。
  2. http://nunit.org/docs/2.5/consoleCommandLine.html - how you can run your test categories from nunit-console. http://nunit.org/docs/2.5/consoleCommandLine.html-如何从nunit-console运行测试类别。
  3. https://confluence.jetbrains.com/display/TCD9/Getting+Started+with+NUnit#GettingStartedwithNUnit-Case1.CommandLine - how you could use nunit-console inside team city. https://confluence.jetbrains.com/display/TCD9/Getting+Started+with+NUnit#GettingStartedwithNUnit-Case1.CommandLine-如何在团队城市中使用nunit-console。

Second approach: 第二种方法:

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

Turns out TeamCity supports separation of test assemblies by individual test runner processes - option called 'Run process per assembly' in NUnit build step configuration: 事实证明,TeamCity支持按单个测试运行程序进程分离测试程序集-NUnit构建步骤配置中称为“每个程序集运行过程”的选项:

每个程序集运行流程

More details here: https://confluence.jetbrains.com/display/TCD10/NUnit (search 'Run process per assembly') 此处有更多详细信息: https : //confluence.jetbrains.com/display/TCD10/NUnit (搜索“每个部件的运行过程”)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM