测试夹具参数的 NUnit 测试名称模板是什么? [英] What is the NUnit test name template for the test fixture arguments?

查看:51
本文介绍了测试夹具参数的 NUnit 测试名称模板是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以 {a} 指的是测试用例参数,但是在测试用例的全名中我们可以看到测试夹具参数.例如:

So {a} refers to the test case arguments, but in the full name of the test case we can see the test fixture arguments. For example:

C:\DFDeploymentSmokeTests\LocalTestProfiles> $xml = [xml](cat ..\TestResults\CSTests.xml)
C:\DFDeploymentSmokeTests\LocalTestProfiles> $TestCase = $xml.SelectSingleNode('//test-case')
C:\DFDeploymentSmokeTests\LocalTestProfiles> $TestCase.name
SiteCheck
C:\DFDeploymentSmokeTests\LocalTestProfiles> $TestCase.fullname
Web.ForEachWebServer(nan4dfc1app01_10.192.78.221_smoketest.dayforce.com).SiteCheck
C:\DFDeploymentSmokeTests\LocalTestProfiles>

nan4dfc1app01_10.192.78.221_smoketest.dayforce.com 是 Test Fixture 参数的 ToString() 结果,NUnit 将其包含在测试用例的全名中.

The nan4dfc1app01_10.192.78.221_smoketest.dayforce.com is the ToString() result of the Test Fixture argument and NUnit includes it in the fullname of a test case.

但是,似乎没有办法在--test-name-format 命令行参数中提供它.

However, there does not seem to be a way to provide it in the --test-name-format command line parameter.

或者我错了,有办法吗?

Or am I wrong and there is a way?

澄清

我不想更改测试的全名,而只想更改其名称.我的问题是使用 TestFixtureSource 的夹具下的测试名称.事实上,假设夹具名称是 F,它下的测试是 T1T2 并且夹具被调用两次,参数为 A1A2.默认的测试名称模式是 {m}{a},但 {a} 不包括夹具参数.所以,测试报告显示了这些测试名称(不是全名):

I do not want to change the full name of a test, but just its name. My problem is with the test names under a fixture using TestFixtureSource. Indeed, suppose the fixture name is F, the tests under it are T1 and T2 and the fixture is invoked twice with arguments A1 and A2. The default test name pattern is {m}{a}, but {a} does not include the fixture parameters. So, the test report shows these test names (not full names):

T1 
T2 
T1
T2

这是它在 Azure DevOps 测试中的显示方式(发布测试插件在发布结果时使用测试名称)

This is how it shows in the Azure DevOps Tests (the Publish Tests plugin uses the test names when publishing the results)

我想把名字改成全名,因为全名是:

I want to change the name to be equal to the full name, because the full names are:

F(A1).T1
F(A1).T2
F(A2).T1
F(A2).T2

我意识到如果名称是 F(A1).T1,那么全名将是 F(A1).F(A1).T1,但由于 UI 没有显示全名,我可以接受.

I realize that if the name would be F(A1).T1, then the full name would be F(A1).F(A1).T1, but since UI does not show the full names, I can live with that.

推荐答案

测试用例的全名始终是附加到包含类的全名的名称(默认或由您设置).没有办法改变这一点.

The full name of a test case is always the name (default or set by you) appended to the full name of the containing class. There is no way to change this.

更新:根据您的说明,您希望测试用例名称包含传递给特定夹具实例的参数.这也是不可能的,使用目前的静态"设计.

UPDATE: Based on your clarification,you want the test case name to include the parameters passed to the particular fixture instance. This is also impossible, using the current "static" design.

[此处以特殊的 NUnit-y 方式使用静态"和动态".从某种意义上说,所有这些都是动态的,因为它会在您执行 runner 时发生.但我们用它来表示在测试加载(创建、发现)时预先确定,而不是在每次测试执行时确定."]

[Using "static" and "dynamic" in a special NUnit-y way here. In a sense, all of this is dynamic, since it happens when you execute the runner. But we use it to mean "predetermined when the test is loaded (created, discovered) as opposed to "determined at each test execution."]

在您的测试被发现(并命名)时没有固定装置尚未实例化.运行您的 TestCaseSource 方法的代码正在生成用于每个测试装置实例的测试名称.我们本可以用不同的方式来做,但是......好吧,我们没有,因为没有人想到这个用例.

At the time your tests are discovered (and named) no fixtures have been instantiated yet. The code that runs your TestCaseSource method is generating test names to be used for each instance of the test fixture. We could have done it differently, but... well, we didn't because nobody thought of this use case.

对不起!

PS:NUnit 存在一个长期存在的问题,需要创建(我们称之为)动态"测试用例,其中可以轻松包含您要求的功能.

PS: There is a long-standing NUnit issue calling for the creation of (what we call) "dynamic" test cases, which could easily include the feature you are asking for.

这篇关于测试夹具参数的 NUnit 测试名称模板是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆