SpecFlow icon indicating copy to clipboard operation
SpecFlow copied to clipboard

SpecFlow doesn't support xunits `BeforeAfterTestAttribute`

Open baynezy opened this issue 3 years ago • 6 comments

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

baynezy avatar May 23 '22 12:05 baynezy

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 avatar May 23 '22 13:05 SabotageAndi

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.

SabotageAndi avatar May 23 '22 14:05 SabotageAndi

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

baynezy avatar May 24 '22 07:05 baynezy

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 avatar May 24 '22 07:05 SabotageAndi

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

SabotageAndi avatar May 24 '22 07:05 SabotageAndi

That's incredible. Thanks.

baynezy avatar May 24 '22 08:05 baynezy

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

kaylumah avatar Aug 10 '22 18:08 kaylumah

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

SabotageAndi avatar Aug 11 '22 14:08 SabotageAndi

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.

github-actions[bot] avatar Sep 11 '22 00:09 github-actions[bot]