Unable to run tests using SpecFlow with `dotnet test` on solution with central NuGet package management
SpecFlow Version
3.9.42
Which test runner are you using?
xUnit
Test Runner Version Number
2.4.3
.NET Implementation
.NET 6.0
Project Format of the SpecFlow project
Classic project format using <PackageReference> tags
.feature.cs files are generated using
Unknown
Test Execution Method
Command line – PLEASE SPECIFY THE FULL COMMAND LINE
SpecFlow Section in app.config or content of specflow.json
{
"bindingCulture": {
"name": "de-de"
},
"language": {
"feature": "de-de"
},
"runtime": {
"missingOrPendingStepsOutcome": "Ignore"
},
"livingDocGenerator": {
"enabled": true,
"filePath": "TestExecution.json"
}
}
Issue Description
We switched our solution to NuGet Central Package Management. Now we are unable to execute the tests with dotnet test on the test project using SpecFlow. Running dotnet test does not build the project, running dotnet build builds but dotnet test afterward still does not execute the tests. TestExecution.json is also not created. It runs with dotnet vstest, with vstest.console.exe and with Visual Studio 2022 17.4 test runner. All other tests not using SpecFlow (UnitTests) are running with dotnet test.
Steps to Reproduce
Create Directory.Packages.props with package versions and remove package version from csproj. Examples below.
Directory.Packages.props
<Project>
<PropertyGroup>
<LangVersion>latest</LangVersion>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<RunAnalyzersDuringBuild>False</RunAnalyzersDuringBuild>
<RunAnalyzersDuringLiveAnalysis>False</RunAnalyzersDuringLiveAnalysis>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Microsoft.EntityFrameworkCore.InMemory" Version="6.0.3"/>
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.0.0"/>
<PackageVersion Include="Moq" Version="4.16.1"/>
<PackageVersion Include="SolidToken.SpecFlow.DependencyInjection" Version="3.9.2"/>
<PackageVersion Include="SpecFlow.Plus.LivingDocPlugin" Version="3.9.42"/>
<PackageVersion Include="SpecFlow.xUnit" Version="3.9.40"/>
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
</Project>
Tests.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<CodeAnalysisRuleSet>..\Tms.ruleset</CodeAnalysisRuleSet>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="Moq" />
<PackageReference Include="SolidToken.SpecFlow.DependencyInjection" />
<PackageReference Include="SpecFlow.xUnit" />
<PackageReference Include="SpecFlow.Plus.LivingDocPlugin" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio" />
</ItemGroup>
<ItemGroup>
<None Update="specflow.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
Run dotnet test. Project do not compile, bin Folder is empty. Run dotnet build, project compile but TestExecution.json is not created, afterward run dotnet test, tests are not executed.
Link to Repro Project
No response
Any movement on this? Its affecting our team as well.
I have the same issue any help
I had the same problem. I was running SpecFlow with xUnit.
- I removed xUnit by uninstalling SpecFlow.xUnit.
- Instead i've installed mstest by:
- Installing SpecFlow.MsTest
- Installing MSTest.TestAdapter
- Installing MSTest.TestFramework
My philosophy is: If you want Microsoft stuff to work, put as much microsoft stuff in the equation as possible. (When in doubt, choose a microsoft component...)
Obviously, you'll need to make sure every generated *.feature.cs file that contains xunit tests has been removed after building the solution.
Now, when I run dotnet test, it discovers and runs the tests.
Hope this helps anyone!