无法识别的元素 unitTestProvider

Unrecognized element unitTestProvider

我是 SpecFlow 的新手,我使用 SpecFlow 包和 SpecFlow 附加包(NUnit 附带)的基本贡献进行安装。

添加我的功能文件后,我在使用自定义工具生成 SpecFlowsingleFilegenerations 时遇到了一些问题(我通过从属性中删除一个选项来解决这些问题)

然后当我重建解决方案时。它在 unittestprovider

的 appconfig 文件中显示了一些无法识别的元素

error :[SpecFlow] System.Configuration.ConfigurationErrorsException: Unrecognized element 'unitTestProvider'.

我的 appconfig 文件 specflow 部分

<specFlow>
    <unitTestProvider name="NUnit" />
    <plugins>
      <add name="Baseclass.Contrib.SpecFlow.Selenium.NUnit" path="..\packages\Baseclass.Contrib.SpecFlow.Selenium.NUnit.1.3.1\tools" /> 
    </plugins>

  </specFlow>

该配置文件不适用于 SpecFlow 3.0 及更高版本。您可以阅读有关如何更新到 3.0 here 的文档。它说:

Changes to How Unit Test Providers are Configured

In previous versions of SpecFlow, the unit test provider used to execute tests was configured in your app.config file. As of SpecFlow 3, we strongly recommend configuring your unit test provider by installing one of the available packages (see below).

还有:

specflow.json

Moving forward, we recommend using specflow.json to configure SpecFlow, rather than app.config. .NET Core projects require specflow.json (app.config is not supported). While using specflow.json is optional for Full Framework projects, we recommend migrating to the new format. For more details, see Configuration in the documentation.

因此您可以从 app.config 中删除 SpecFlow 并创建一个名为 specflow.json 的文件。您可以将以下内容放入其中:

{
    "language": {
        "feature": "en-US"
    }
}

如果需要,您可以将语言更改为其他语言。

您必须将测试运行器添加到您的项目中(如果您还没有的话)。在您的情况下,它是 NUnit,因此使用 NuGet 添加 SpecFlow.NUnit。对于 NUnit,您通常需要 example project 中列出的包。

所以我通过以下步骤解决了同样的问题:

  1. 转到管理解决方案的 nugget 包,并在显示版本 3.1.97(自行更新)的安装下查找规范流卸载并为整个项目安装版本 3.1.76,包括测试框架(规范流)。

  2. 对于Specflow.nunit卸载并安装3.1.76版但不是测试框架(取消选中它旁边的框)但其他项目应该已经恢复。

  3. 对 Specflow.Tools.Msbuild.geneartion 执行与步骤 2 相同的操作并重新启动计算机。