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

_unitTestRuntimeProvider.TestIgnore sets the step as failed, witch presents as error in the Livingdoc report #2699

Open renycorreia opened 1 year ago

renycorreia commented 1 year ago

SpecFlow Version

3.9.74

Which test runner are you using?

xUnit

Test Runner Version Number

3.9.74

.NET Implementation

.NET 6.0

Project Format of the SpecFlow project

Sdk-style project format

.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

 {
  "bindingCulture": {
    "name": "pt-br"
  },
  "language": {
    "feature": "pt-br"
  },
  "stepAssemblies": [
    {
      "assembly": "projectName.crosscutting.ioc"
    }
  ],
  "livingDocGenerator": {
    "enabled": true,
    "filePath": "TestExecution.json"
  }
}

Issue Description

.NET Implementation

.NET 7.0 right now, but I had the same issue using .NET 6.0

SpecFlow+ LivingDoc Version

3.9.57
I've configured some tests to be ignored, based a few conditions, using _unitTestRuntimeProvider.TestIgnore("some message") in one of the steps. It works fine, except that the step and the scenario were set as failed.

I was able to change the scenario state to Skipped using the code below at the AfterScenario hook.

    if (_scenarioContext.TestError != null && _scenarioContext.TestError.ToString().Contains("[some message]"))
    {
        PropertyInfo testStatusProperty = (typeof(ScenarioContext)).GetProperty("ScenarioExecutionStatus", BindingFlags.Instance | BindingFlags.Public);
        PropertyInfo testErrorProperty = typeof(ScenarioContext).GetProperty("TestError", BindingFlags.Instance | BindingFlags.Public);

        testStatusProperty.SetValue(_scenarioContext, ScenarioExecutionStatus.Skipped);
        testErrorProperty.SetValue(_scenarioContext, null);
    }

However, the step is taken as as failed, as can be seen in the json snippet below .

image

This causes the Analytics tab of the Livingdoc report to indicate that there is a failed step. Even though there is no failed scenario or feature.

image

Is there a way of doing this without indicating that the step is failed?

Steps to Reproduce

Link to Repro Project

No response

Myvryn commented 1 year ago

I've been seeing the same issue. It would be nice to get this fixed so that we can have Inconclusive rather than failed.

Moshex commented 1 year ago

Same, it would be nice if the inhouse test ignore did not show as a fail on the report

JDunn3 commented 1 year ago

This is a major issue for anyone with >10 tests in various feature files that they must dynamically ignore.