GHPReporter / Ghpr.NUnit

Adapter for NUnit 3 (generate HTML report for NUnit 3)
http://ghpreporter.github.io/
MIT License
35 stars 14 forks source link

NUnit Data Driven Results display incorrectly #23

Closed jacobwiseman closed 7 years ago

jacobwiseman commented 7 years ago

Using the new NUnit TextFixtureSourceattribute AND feeding in complex objects as structured data-driven test input, the results as displayed in GHPReporter on the run-test-list page.

Instead of displaying the real test namespace hierarchy, GHPReporter is using the namespace of the input objects as well.

capture

elv1s42 commented 7 years ago

Hi @UltimateWombat

I will try to reproduce this issue. But in general, test list is generated by splitting test's full name (where '.' is used as separator). Probably it is just the NUnit creates full name for tests with TextFixtureSource

In any case, thank you for this issue, I will let you know about the results of my investigation.

jacobwiseman commented 7 years ago

On the TestHistory tab, the test's Full Name is displayed as Quality.Automation.Tests.ClientApiTests(3,System.Collections.Generic.Dictionary'2[System.String,System.String],Quality.Automation.QueryObjects.ClientApi.MyObject.MyPayload,Quality.Automation.QueryObjects.ClientApi.Models.MyOtherObject.MyOtherPayload,Quality.Automation.QueryObjects.Tools.Models.ThirdPayload).testFindOrCreateSomething

Note that the majority of this Full Name is the input parameters. The actual test Full Name is simply Quality.Automation.Tests.ClientApiTests.testFindOrCreateSomething. So in reality, anything between the parentheses should be ignored.

elv1s42 commented 7 years ago

Hello again!

I think I found how to resolve this issue. When you are using complex objects as structured data-driven test input NUnit generates Test full name by calling .ToString() method for your object. According to MSDN, the default implementation of the ToString method returns the fully qualified name of the type: 2017-04-18 15_38_26- object tostring system

I've created sample tests to reproduce this: 2017-04-18 15_39_30-ghpr nunitexamples - microsoft visual studio And as expected, I recieved wrong test list: 2017-04-18 15_40_35-ghp report run page Here is full name of the test: 2017-04-18 15_42_24-ghp report test page

Then I've added new .ToString() method: 2017-04-18 15_44_29-ghpr nunitexamples - microsoft visual studio And new test list looked much better: 2017-04-18 15_45_42-ghp report run page Because full name changed: 2017-04-18 15_46_28-ghp report test page

elv1s42 commented 7 years ago

So basically you can try to override 'ToString()' method for your complex objects.

jacobwiseman commented 7 years ago

This works for custom objects, however if I am passing something like a Dictionary then the System.Collections.Generic.Dictionary namespace is passes. I'd rather not have to extend the Dictionary class simply to overwrite the toString method.

Could you perhaps ignore any of the namespace strings between the starting ( and ending ) that designates the input parameters?

elv1s42 commented 7 years ago

Yes, this is possible. Will do this with the next release for Ghpr.Core because this test list is generated by javascript controller.

jacobwiseman commented 7 years ago

Excellent, thanks!

elv1s42 commented 7 years ago

Hello again! I am afraid we have some issues with this fix.

  1. First of all, if we ignore any of the namespace strings between the starting ( and ending ) for our case, we can brake another cases like this (and for several cases for Ghpr.SpecFlow.Plugin): 2017-04-18 19_19_04-ghpr nunitexamples - microsoft visual studio 2017-04-18 19_19_55-ghp report run page

  2. Second one is related to test history. When our test is finished, we are creating Guid for our test. This Guid is created from test's full name, so we are expect this name to be unique. but for your case full name will not be unique.

So I think we need another approach for resolving this issue.

jacobwiseman commented 7 years ago
  1. In the test.json file there are 2 fields in the json. name and fullName. It seems that if you could:

    • filter out the namespace strings between the starting ( and ending ) from fullname for organization & sorting purposes on the run-test-list tab
    • but still use the name field to display the test to the user.
  2. I don't see how this is any different than the original problem. If I was only sending in a complex object without a ToString() override before, then the fullName was already non-unique.

elv1s42 commented 7 years ago
  1. Agree, this is what will be done.

  2. I would suggest using override method to get unique test name.

elv1s42 commented 7 years ago

Hi,

  1. Fixed in new release.
  2. I would suggest using override method to get unique test name: http://stackoverflow.com/a/2024193/4185987