Open InspiringCode opened 5 years ago
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:
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?
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:
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.
@InspiringCode is it better if you switch on "Show Test Hierarchy"?
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?
@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.
@InspiringCode have you managed to get things working satisfactorily now or do you have any remaining concerns?
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.
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
I would like to see just
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!