【问题标题】:The "GenerateFeatureFileCodeBehindTask" task failed unexpectedly. System.Exception: Unit test Provider already set“GenerateFeatureFileCodeBehindTask”任务意外失败。 System.Exception:单元测试提供程序已设置
【发布时间】:2021-11-09 05:44:46
【问题描述】:

我在 .NET Core 3.1 中安装了一些 specflow 包

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

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="FluentAssertions" Version="6.1.0" />
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
    <PackageReference Include="SpecFlow.Tools.MsBuild.Generation" Version="3.9.22" />
    <PackageReference Include="SpecFlow.xUnit" Version="3.9.22" />
    <PackageReference Include="SpecRun.SpecFlow" Version="3.9.7" />
  </ItemGroup>

  <ItemGroup>
    <Folder Include="Hooks\" />
  </ItemGroup>    

</Project>

但是当我构建时,我得到了这个错误:

Severity    Code    Description Project File    Line    Suppression State
Error   MSB4018 The "GenerateFeatureFileCodeBehindTask" task failed unexpectedly.
System.Exception: Unit test Provider already set.
   at TechTalk.SpecFlow.UnitTestProvider.UnitTestProviderConfiguration.UseUnitTestProvider(String unitTestProviderName)
   at TechTalk.SpecFlow.xUnit.Generator.SpecFlowPlugin.GeneratorPlugin.Initialize(GeneratorPluginEvents generatorPluginEvents, GeneratorPluginParameters generatorPluginParameters, UnitTestProviderConfiguration unitTestProviderConfiguration) in D:\a\1\s\Plugins\TechTalk.SpecFlow.xUnit.Generator.SpecFlowPlugin\GeneratorPlugin.cs:line 14

【问题讨论】:

    标签: c# asp.net-core specflow


    【解决方案1】:

    在 SpecFlow 项目中不能同时安装 SpecRun.SpecFlow 和 SpecFlow.NUnit。它们用于配置使用哪个单元测试运行器。

    我假设您在创建 SpecFlow 项目时选择了 SpecFlow+ Runner。这会添加 SpecRun.SpecFlow NuGet 包。

    当您手动添加 SpecFlow.NUnit 包时,您会收到此错误。 您可以在项目向导中选择 NUnit,以使用 NUnit 启动项目。

    这种行为自 SpecFlow 3.0 起就存在。

    单元测试提供者的文档:https://docs.specflow.org/projects/specflow/en/latest/Installation/Unit-Test-Providers.html

    【讨论】:

      猜你喜欢
      • 2020-06-30
      • 2020-11-10
      • 1970-01-01
      • 1970-01-01
      • 2023-01-19
      • 2021-12-04
      • 2018-01-02
      • 2017-09-20
      • 2013-05-25
      相关资源
      最近更新 更多