microsoft / testfx

MSTest framework and adapter
MIT License
752 stars 256 forks source link

What is the intended purpose for the hierarchy provided in TestNode? #2537

Open bradwilson opened 8 months ago

bradwilson commented 8 months ago

When reporting TestNode updates, you can include the parent test node UID. Looking at the code in Microsoft.Testing.Extensions.VSTestBridge for examples, it doesn't appear that any reporting there is using any hierarchy.

What do you envision the purpose of that hierarchy is, and how would it be reported to the user in Test Explorer? xUnit.net, for example, can make a case for its hierarchy being Assembly > Test Collection > Test Class > Test Method > Test Case > Test. Would it make sense for us to report all of that? Some of that? None of that?

Experimentation with dotnet test today shows that none of that appears to be used at the moment. Reporting parentless test results, just like the VSTestBridge, results in successful execution:

  $ .\src\xunit.v3.assert.tests\bin\Debug\net6.0\xunit.v3.assert.tests.exe

xUnit.net v3 In-Process Runner v0.1.1-pre.379-dev+f22e679603 (64-bit .NET 6.0.27)
  Discovering: xunit.v3.assert.tests (method display = ClassAndMethod, method display options = None)
  Discovered:  xunit.v3.assert.tests (1122 test cases to be run)
  Starting:    xunit.v3.assert.tests (parallel test collections = on [24 threads], stop on fail = off, explicit = off, seed = 1016941239, culture = invariant)
  Finished:    xunit.v3.assert.tests
=== TEST EXECUTION SUMMARY ===
   xunit.v3.assert.tests  Total: 1353, Errors: 0, Failed: 0, Skipped: 0, Not Run: 0, Time: 0.163s
  $ dotnet test src\xunit.v3.assert.tests --framework net6.0

  Determining projects to restore...
  All projects are up-to-date for restore.
  xunit.v3.assert -> C:\Dev\xunit\xunit\src\xunit.v3.assert\bin\Debug\net6.0\xunit.v3.assert.dll
  xunit.v3.common -> C:\Dev\xunit\xunit\src\xunit.v3.common\bin\Debug\netstandard2.0\xunit.v3.common.dll
  xunit.v3.core -> C:\Dev\xunit\xunit\src\xunit.v3.core\bin\Debug\netstandard2.0\xunit.v3.core.dll
  xunit.v3.runner.common -> C:\Dev\xunit\xunit\src\xunit.v3.runner.common\bin\Debug\netstandard2.0\xunit.v3.runner.common.dll
  xunit.v3.runner.inproc.console -> C:\Dev\xunit\xunit\src\xunit.v3.runner.inproc.console\bin\Debug\net6.0\xunit.v3.runner.inproc.console.dll
  xunit.v3.runner.utility -> C:\Dev\xunit\xunit\src\xunit.v3.runner.utility\bin\Debug\netstandard2.0\xunit.v3.runner.utility.netstandard20.dll
  xunit.v3.runner.tdnet -> C:\Dev\xunit\xunit\src\xunit.v3.runner.tdnet\bin\Debug\netstandard2.0\xunit.v3.runner.tdnet.dll
  xunit.v3.runner.tdnet -> C:\Dev\xunit\xunit\src\xunit.v3.runner.tdnet\bin\Debug\netstandard2.0\merged\xunit.v3.runner.tdnet.dll
  xunit.v3.assert.tests -> C:\Dev\xunit\xunit\src\xunit.v3.assert.tests\bin\Debug\net6.0\xunit.v3.assert.tests.dll
  Run tests: 'C:\Dev\xunit\xunit\src\xunit.v3.assert.tests\bin\Debug\net6.0\xunit.v3.assert.tests.dll' [net6.0|x64]
  Tests succeeded: 'C:\Dev\xunit\xunit\src\xunit.v3.assert.tests\bin\Debug\net6.0\xunit.v3.assert.tests.dll' [net6.0|x64]

  $ cat src\xunit.v3.assert.tests\bin\Debug\net6.0\TestResults\xunit.v3.assert.tests_net6.0_x64.log

Microsoft(R) Testing Platform Execution Command Line Tool
Version: 1.0.2+1686a9c93 (UTC 2024/02/21)
RuntimeInformation: win10-x64 - .NET 6.0.27
Copyright(c) Microsoft Corporation.  All rights reserved.
  Discovering: xunit.v3.assert.tests (method display = ClassAndMethod, method display options = None)
  Discovered:  xunit.v3.assert.tests (1122 test cases to be run)
  Starting:    xunit.v3.assert.tests (parallel test collections = on [24 threads], stop on fail = off, explicit = off, seed = 1016941239, culture = invariant)
  Finished:    xunit.v3.assert.tests
=== TEST EXECUTION SUMMARY ===
   xunit.v3.assert.tests  Total: 1353, Errors: 0, Failed: 0, Skipped: 0, Not Run: 0, Time: 0.158s
Passed! - Failed: 0, Passed: 1353, Skipped: 0, Total: 1353, Duration: 320ms - xunit.v3.assert.tests.dll (win10-x64 - .NET 6.0.27)

=== COMMAND LINE ===
C:\Program Files\dotnet\dotnet.exe exec C:\Dev\xunit\xunit\src\xunit.v3.assert.tests\bin\Debug\net6.0\xunit.v3.assert.tests.dll --internal-msbuild-node testingplatform.pipe.ae8e4422d11c4007b5802f10ca515653

I have not attempted to add any hierarchy (this is just experimental work at the moment), but I'm not sure how dotnet test would interpret that currently. Let's assume a single level of hierarchy (Assembly > Test) was supported. Would I report the assembly as "in progress", then at the end, report it as "failed" or "passed" based on whether any tests failed? How would that contribute to the test count in dotnet test? The API description of test node includes a node type of action vs. group (it would make sense that everything that's not a running test would be a group), but I don't see that reflected into the TestNode object in Microsoft.Testing.Platform. I'm presuming that every TestNode is implicitly an action node type right now; is that correct? So is it not possible to reporting groupings today?

Evangelink commented 8 months ago

What do you envision the purpose of that hierarchy is, and how would it be reported to the user in Test Explorer? xUnit.net, for example, can make a case for its hierarchy being Assembly > Test Collection > Test Class > Test Method > Test Case > Test. Would it make sense for us to report all of that? Some of that? None of that?

We have designed this new testing principles by trying to be as open as possible to the various scenario we could see in testing in general (not .NET specific) and it seems that supporting a tree of tests is what's most generic as it allows flat list (as VSTest), test group and tests (as in F# Expecto for example), it supports BDD (like SpecFlow) and also Behavior Trees like automation/Unity... And so we have done something similar for the protocol.

The main problem is that Test Explorer (VS and VS Code) doesn't support this. We have some discussions with the team owning this part and we hope we will be able to make this component evolve in the future but there is currently no short-term plan for it.

So as of now, we have the support for this hierarchical feature in the platform and the protocol but no way to display it. We are considering alternatives if there is no way to make Test Explorer move quickly but this is still under discussion.

Would I report the assembly as "in progress", then at the end, report it as "failed" or "passed" based on whether any tests failed?

If we remove any existing constraint, we are still having some discussions about that. My thinking is that I would want any test framework to be able to have full control/customization so yes you would/could report any node as anything based upon the logic you want. Some concerns were raised that devs are used to the current model and that they would expect similar behavior across test frameworks.

The API description of test node includes a node type of action vs. group (it would make sense that everything that's not a running test would be a group), but I don't see that reflected into the TestNode object in Microsoft.Testing.Platform. I'm presuming that every TestNode is implicitly an action node type right now; is that correct? So is it not possible to reporting groupings today?

Because of the current limits of Test Explorer and because the main usage for now are matching old models, we are short-circuiting and considering any node to be an action. But the idea we had is to say this would be another property of the reported nodes.