What is the NUnit test name template for the test fixture arguments?

南笙酒味 提交于 2019-12-13 04:18:23

问题


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>

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.

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?

Clarification

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

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

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.


回答1:


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.

[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."]

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.

Sorry!

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.



来源:https://stackoverflow.com/questions/54489945/what-is-the-nunit-test-name-template-for-the-test-fixture-arguments

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