SpecFlow icon indicating copy to clipboard operation
SpecFlow copied to clipboard

Colorize test output

Open Socolin opened this issue 2 years ago • 2 comments

Link to Feature Request

No response

Implementation Idea

Hello,

I would like to add some colors in the specflow output, it'll make it simpler and easier to find what step failed when reading the test output. Since Visual Studio does not support it this feature would impact only Rider users and test output on build servers (dotnet test)

Here a preview of what it can look like image

By default this feature would be disabled (so it does not break anything) then people could enable it with the config trace.coloredOutput

If the color is problematic in some context it's possible to disable it with NO_COLOR environment variable (https://no-color.org/).

For teams using Rider and VS I would need a bit of help to find a way to detect if the execution is done through VS (I don't have VS so I cannot do test, but maybe there is an environment variables set we can use to detect it, otherwise since Rider allow to provide custom env variable in test runner we could add a FORCE_COLOR too, ignoring the configuration)

I have a WIP so you can test it already, I'll wait to get some feedback before writting test & co https://github.com/Socolin/SpecFlow/commits/color-output

The colors can be configure by injecting IColorOutputTheme so users can decide programatically the colors and adjust if needed (or add Bold / underline etc...) I don't know if we want to allow the color to be configure with specflow.json too

[Binding]
public class Hooks
{
	[BeforeTestRun]
	public static void ConfigureColor(IColorOutputTheme colorOutputTheme)
	{
		colorOutputTheme.Keyword = AnsiColor.Reset;
		colorOutputTheme.Error = AnsiColor.Composite(AnsiColor.Bold, AnsiColor.Foreground(TerminalRgbColor.FromHex("FF8EF3")));
		colorOutputTheme.Done = AnsiColor.Foreground(TerminalRgbColor.FromHex("3A86FF"));
	}
}

Would give an output like image

Notes

in dotnet test NUnit and xUnit are currently escaping color codes so to test without rider I would recommend to use MSTest for now. I'm working on a fix for NUnit and I opened an issue for xUnit

Socolin avatar Jun 12 '22 01:06 Socolin

@gasparnagy your two cents to this?

I am fine with this.

SabotageAndi avatar Jun 13 '22 12:06 SabotageAndi

Looks interesting. We can try in an opt-in fession without too much risk... @Socolin could you please try to make a PR for this so that it is easier to review/test the changes?

gasparnagy avatar Jun 13 '22 12:06 gasparnagy