SpecFlowOSS / SpecFlow

#1 .NET BDD Framework. SpecFlow automates your testing & works with your existing code. Find Bugs before they happen. Behavior Driven Development helps developers, testers, and business representatives to get a better understanding of their collaboration
https://www.specflow.org/
Other
2.24k stars 754 forks source link

[AfterTestRun] Console.WriteLine does not appear in report #2532

Closed Naweap closed 2 years ago

Naweap commented 2 years ago

SpecFlow Version

3.9.7

Which test runner are you using?

SpecFlow+ Runner

Test Runner Version Number

3.9.7

.NET Implementation

.NET Core 3.1

Project Format of the SpecFlow project

Classic project format using packages.config

.feature.cs files are generated using

SpecFlow.Tools.MsBuild.Generation NuGet package

Test Execution Method

Visual Studio Test Explorer

SpecFlow Section in app.config or content of specflow.json

No response

Issue Description

I would like to output some information in the report when all tests have been executed. I used the [AfterTestRun] hook to do that.

Unfortunately, my Console.WriteLine output does not seem to appear in the report. Even when I'm printing some basic informations eg :

[AfterTestRun]
public static void AfterTestRun(ITestRunnerManager testRunnerManager, ITestRunner testRunner)
{
    Console.WriteLine("blablabla");
}

So I had to use the [AfterStep] hook and do tricky in order to archive my goal.

Are you aware of this issue and is there a solution to be able to print informations inside my report from the [AfterTestRun] hook ?

Thanks in advance

Steps to Reproduce

[AfterTestRun]
public static void AfterTestRun(ITestRunnerManager testRunnerManager, ITestRunner testRunner)
{
    Console.WriteLine("blablabla");
}

Link to Repro Project

No response

DomZZ commented 2 years ago

You can inject ISpecFlowOutputHelper and then call WriteLine method that will output the message into the report.

Naweap commented 2 years ago

You can inject ISpecFlowOutputHelper and then call WriteLine method that will output the message into the report.

I actually have the following code :

[AfterTestRun]
public static void AfterTestRun(ISpecFlowOutputHelper specFlowOutputHelper)
{
    specFlowOutputHelper.WriteLine("blablabla");
    //Console.WriteLine("blablabla");
}

It goes through the AfterTestRun function but doesn't display the given string inside the report.

Note : I use a custom report template

SabotageAndi commented 2 years ago

The SpecFlow+Runner implementation of the ISpecFlowOutputHelper uses Console.WriteLine in the background. So there is no difference. Output in the TestRun hooks aren't displayed, because it can't be assigned to a scenario. It is the same for Feature hooks.

You have this problem with all test runners. It is not limited to the SpecFlow+Runner.

github-actions[bot] commented 2 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.