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.23k stars 752 forks source link

SpecFlow doesn't support xunits `BeforeAfterTestAttribute` #2601

Closed baynezy closed 1 year ago

baynezy commented 2 years ago

SpecFlow Version

3.9.22

Which test runner are you using?

xUnit

Test Runner Version Number

3.9.22

.NET Implementation

.NET 5.0

Project Format of the SpecFlow project

Classic project format using <PackageReference> tags

.feature.cs files are generated using

SpecFlow.Tools.MsBuild.Generation NuGet package

Test Execution Method

Command line – PLEASE SPECIFY THE FULL COMMAND LINE

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

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <TargetFramework>net6.0</TargetFramework>
        <Nullable>enable</Nullable>
        <ImplicitUsings>enable</ImplicitUsings>
    </PropertyGroup>

    <ItemGroup>
        <Using Include="TechTalk.SpecFlow" />
    </ItemGroup>

    <ItemGroup>
        <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
        <PackageReference Include="SpecFlow.Plus.LivingDocPlugin" Version="3.9.57" />
        <PackageReference Include="SpecFlow.xUnit" Version="3.9.22" />
        <PackageReference Include="Verify.Xunit" Version="16.7.1" />
        <PackageReference Include="xunit" Version="2.4.1" />
        <PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
            <PrivateAssets>all</PrivateAssets>
            <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
        </PackageReference>
        <PackageReference Include="FluentAssertions" Version="6.2.0" />
    </ItemGroup>

    <ItemGroup>
      <ProjectReference Include="..\..\src\Example\Example.csproj" />
    </ItemGroup>

</Project>

Issue Description

I am trying to use the Verify testing library with SpecFlow. Sadly it is incompatible as it appears SpecFlow does not support xunits BeforeAfterTestAttribute

I have this confirmed by the project lead on Verify in this PR he helped me with.

Is this something that would be supported?

Steps to Reproduce

Checkout this repro case

Run dotnet test

Link to Repro Project

https://github.com/baynezy/SpecFlowVerifyIssue

SabotageAndi commented 2 years ago

You learn every day something new. I am using xUnit for years, but I never heard until now about the BeforeAfterTestAttribute. I have to look into it, what it is and why it doesn't work.

SabotageAndi commented 2 years ago

Ok, found the issue. The [UsesVerify] attribute has to be on the generated test classes and not on the binding classes.

Should be not that hard to create a generator plugin that adds it to the generated code.

baynezy commented 2 years ago

Thanks @SabotageAndi I have been looking at what is involved for this. I have some questions, but joining the Discord channel link at the bottom of the page keeps failing. Can you help?

image

SabotageAndi commented 2 years ago

Ok, Discord Link was broken. This is the right one: https://discord.com/invite/xQMrjDXx7a

I started yesterday to quickly create a plugin for this. I hope I can finish it today or tomorrow.

SabotageAndi commented 2 years ago

Draft PR is here: https://github.com/SpecFlowOSS/SpecFlow/pull/2602

baynezy commented 2 years ago

That's incredible. Thanks.

kaylumah commented 1 year ago

@SabotageAndi thank you for adding the generator plugin, I think that this one will be something for the long run now?

SabotageAndi commented 1 year ago

So, Verify support is available. Needed NuGet package: https://www.nuget.org/packages/SpecFlow.Verify/4.0.16-beta Example: https://github.com/SpecFlowOSS/SpecFlow-Examples/tree/master/Verify/VerifyExample

github-actions[bot] commented 1 year 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.