Skip to content
This repository has been archived by the owner on Jun 12, 2021. It is now read-only.

Customizing the displayed step names in output/Visual Studio #567

Open
InspiringCode opened this issue May 30, 2019 · 7 comments
Open

Customizing the displayed step names in output/Visual Studio #567

InspiringCode opened this issue May 30, 2019 · 7 comments
Labels
question Further information is requested

Comments

@InspiringCode
Copy link

Is there any way to customize how step names and scenario names are displayed? I would really find it useful to just see the sequence and name of the step without the scenario name prefix. So instead of

"DX.Platform.Infrastructure.EventStore.Mongo.MongoStreamStoreFeature.Save() [09] WHEN getting the saved stream"

I would like to see just

[09] WHEN getting the saved stream"

which would be much more clear and easy to read. Also I would like to just see the class name as the scenario name, without the namespace.

Is there any way I can extend/customize xbehave to achieve this? I would really value this possibility!

@adamralph adamralph added the question Further information is requested label Jun 1, 2019
@adamralph
Copy link
Owner

Hi @InspiringCode, thanks for raising this question.

Regarding the scenario name, you can control that using the DisplayName property of the Scenario attribute, e.g.

[Scenario(DisplayName = nameof(MyClass))]

This will also be reflected in the name of the steps in the scenario, but there is no way to trim those down to only the step number and step text.

However, before embarking on this, it's worth bearing a few things in mind:

  • A given class name could be used more than once, under different namespaces.
  • The class name cannot be used as the scenario name unless there is only one scenario method in the class. If there is more than one scenario method, the name of the method must form part of the scenario name to avoid duplicates names.
  • Various scenario methods can share the same name, but with different parameters. This is why xbehave uses the parameters to the scenario methods in the scenario names.
  • The same step text could be used in various steps in various scenarios. This is why xbehave uses the secnario name as part of the step name.

While you may be able to get away with leaving some of those things out of the step names, you'd have to be very disciplined not to write a scenario or step that results in duplicate names in the final test output. The default algorithm used for building step names in xbehave ensures that you will never see any duplicates. Personally I would recommend against removing any parts of the step names and to leave the default behaviour in place.

Perhaps, if you describe your use case for this, I could suggest an alternative approach? How are you running your tests? In VS? In the command line? Something else? And where and how are you viewing the results?

@InspiringCode
Copy link
Author

Hi @adamralph, thank you very much for your thorough answer.

My use case is simply the Test Explorer of Visual Studio, which I use to run my test. When browsing tests or when I test fails, I quickly want to get a good overview. However, in my Visual Studio 2019 the Test Explorer looks like this:

text_explorer_screenshot

This doesn't look very helpful to me.

Setting the DisplayName strangely ONLY affects the display of the Step Names. In the Tree and in the Title of the Test Details, Visual Studio still displays the full name of the method with class name and namespace (like in the screenshot above).

I would be grateful for any suggestions.

@adamralph
Copy link
Owner

@InspiringCode is it better if you switch on "Show Test Hierarchy"?

image

@InspiringCode
Copy link
Author

Sorry for the confusion, I tried it again now, and suddenly Visual Studio respected the DisplayName property also in the tree and the title. It seems to take a few seconds or a complete test run, or I don't know. But it works now.

Back to the step names: My initial thought was: why do I need a prefix at all? Because at least in Visual Studio, the steps are always listed below the scenario (as a detail view to the scenario), so I already know exactly, to which scenario the belong. Therefore my thought was, why display it then?

@adamralph
Copy link
Owner

@InspiringCode omitting the method name might work for some GUI runners, but it won't work for most CLI runners, such as dotnet test and xunit.console.exe. When a test fails in a CLI runner, only the name of the test is shown in the failure message. Since each xbehave step is a emitted as a distinct xunit test, if the only the step text is shown in the failure message, you will no have no indication to which scenario, class, and namespace that step belongs. The only way to guarantee that a test failure in a CLI runner can be identified is to have the full method name (including namespace and class) as part of the test display name.

@adamralph
Copy link
Owner

@InspiringCode have you managed to get things working satisfactorily now or do you have any remaining concerns?

@InspiringCode
Copy link
Author

Manually assigning shorter Scenario names makes thing a little better, but still it isn't really satisfactory. I would love to see a configuration option or some extension point, where people that are using the Visual Studio IDE can turn the including of the scenario name off (or maybe completely customize the naming in form of a format string or whatever), maybe depending on the fact whether the test are running in the studio or not. That would make the developer experience much nicer in my opinion and it shouldn't need much change in the existing code.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants