docs icon indicating copy to clipboard operation
docs copied to clipboard

Showing the actual value of complex type parameter with NUnit in the reports

Open kuskmen opened this issue 7 years ago • 3 comments

Hi guys, first forgive me if this is not the right place to ask questions, but to me it is most suitable.

I remember that I've seen somewhere in the web about showing actual value of complex type parameter. Bear with me while I explain what I mean.

With this test:

[Test]
public void Post_StakeToDifferetnSelectionsViaBetsBetIdEndpoint_ReturnsCorrectData(
   [ValueSource(typeof(JsonContextCache), nameof(JsonContextCache.RandomThreeUniqueSelecionIds))] string[] selectionIds,
   [ValueSource(typeof(TestData), nameof(TestData.OddStyles))] OddStyle oddStyle, 
   [Values(true, false)] bool logged)

My report is generated as following:

Post_StakeToDifferetnSelectionsViaBetsBetIdEndpoint_ReturnsCorrectData(System.String[],European,True) This also applies for user defined custom types as well.

What I want to achieve however is showing the actual values of this complex type parameters: Post_StakeToDifferetnSelectionsViaBetsBetIdEndpoint_ReturnsCorrectData(["1","2","3"],European,True)

Is it possible using nUnit or I am mistaken that I've seeing this in the web? I've also asked that question on SO - https://stackoverflow.com/questions/47649312/showing-the-actual-value-of-complex-type-parameter-with-nunit-in-the-reports Thanks, kuskmen

kuskmen avatar Dec 05 '17 11:12 kuskmen

To the extent this is something you want to be able to find out about in the docs, this is the right place for the issue. If you were asking us to change how NUnit names tests, then the right place would be under the NUnit framework repository at https://github.com/nunit/nunit

You can change the naming of individual test cases in NUnit in certain circumstances:

  1. When using the [TestCase] attribute, by specifying the SetName property.
  2. When using the [TestCaseSource] attribute, provided the arguments are given by use of TestCaseData instances. Again, the property to use is SetName.

Two drawbacks to the above:

  1. You have to do it one test at a time.
  2. It isn't available at all when specifying arguments using [Values] or [ValueSource].

The general solution that NUnit has always historically advised is to override ToString in the types you are using as arguments. Obviously, when the type is string[] that's not available to you as an option.

Bottom line, there is no way to do this that I can see without a change to NUnit. Such a change has already been requested and is documented as issue nunit/nunit#1382. You're welcome to add comments there to encourage raising the priority of the issue.

I'm leaving this issue open and I think the @nunit/framework-team should take a look at whether what I've explained above needs to be added to the documentation and, if so, where.

CharliePoole avatar Dec 05 '17 12:12 CharliePoole

A relevant issue in nunit3-vs-adapter, https://github.com/nunit/nunit3-vs-adapter/issues/78, had some comments that might be helpful in addressing this issue. In general I think solving this issue will definitely solve that other one.

MSK61 avatar Dec 05 '17 12:12 MSK61

There are special issues when dealing with the Test Explorer, which would be mitigated if we implemented nunit/nunit#1382 but would still exist since it only resolves the problem for arrays but not for other complex types. That's due to the fact that NUnit tolerates duplicated test names, whereas Test Explorer doesn't. For the general case (using any runner, not just the NUnit 3 adapter under Test Explorer) nunit/nunit#1382 is the one to watch.

CharliePoole avatar Dec 05 '17 13:12 CharliePoole