How to configure Teamcity to ignore some tests

橙三吉。 提交于 2021-01-27 03:58:24

问题


There is a way to configure Teamcity to ignore some tests? I need to run these tests only locally, when they are running in Teamcity, must be ignored.

I'm using nunit.

This could be a directive, attribute, etc.


回答1:


You can do this by adding test categories to your tests.

[Category("LocalOnly")]
[Test]
public void MyLocalTest()
{
    // Code omitted for brevity
}

You can then add that category to the NUnit runner's 'NUnit categories exclude:' field in the TeamCity build step.

NUnit categories exclude: LocalOnly




回答2:


TeamCity 9.1 supports NUnit 3 and it opens many other possibilities to select tests for executing or filter them out. I would recommend to use --where=EXPRESSION which allows to use Test Selection Language. Now you can use even regular expressions to specify tests you want to run or exclude.

Examples

Do you want to exclude only one test?

--where="method != 'TestName'"

Do you want to exclude only one test? Don't remember the name exactly but something with "BuggyMethod" (~ means that a regular expression is involved):

--where="method !~ 'BuggyMethod'"

Run all tests defined in one class:

--where="class == 'My.Namespace.ClassName'"

Forget the full namespace? It's not a problem anymore - use a regular expression:

--where="class =~ 'ClassName'"

You can also combine these expressions to achieve a desired effect. Run all tests for the class but exlude all methods which contain "BuggyMethod":

--where="class =~ 'ClassName' and method !~ 'BuggyMethod'"

This approach is much more flexible and avoids any modifications of your code. I don't see a point to use categories anymore, unless your tests are classified using categories.



来源:https://stackoverflow.com/questions/33876192/how-to-configure-teamcity-to-ignore-some-tests

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!