mstest - 如果 [AssemblyInitialize] 已经存在于 Specflow 的测试项目中,则会出错
问题描述
我已经将 Specflow 从 更新3.0.225
到3.1.62
并且我收到了错误Tests_Integration_MSTestAssemblyHooks: Cannot define more than one method with the AssemblyInitialize attribute inside an assembly.
原因显然是我的[AssemblyInitialize]
项目中已经有了这个属性。我该如何解决?
解决方案
原因是 Specflow 在后台生成另一个文件,其中定义了AssemblyInitialize
/AssemblyCleanup
钩子。为了解决这个问题,应该使用 Specflow 提供的钩子,即BeforeTestRun
/ AfterTestRun
。像这样:
[Binding] // add the Binding attribute on the class with the assembly level hooks
public abstract class SeleniumTest
{
// it used to be [AssemblyInitialize]
[BeforeTestRun]
public static void AssemblyInitialize(/* note there is no TestContext parameter anymore */)
{
// ...
}
// it used to be [AssemblyCleanup]
[AfterTestRun]
public static void AssemblyCleanup()
{
// ...
}
}
推荐阅读
- ssh - 在 Coda 中使用 SSH ProxyJump
- flutter - 无法在颤振中使用扩展
- swift - 如何知道您在 Firestore 数据库中有多少个主要集合?
- optimization - Julia:NLsolve 每次运行都提供不同的解决方案,有时会返回 NaN?
- c++ - 如何通过多个类“联合变量”(sfml)使用 pollevent
- node.js - NodeJS 将视频流放在一个元素中
- android - 预期 @AndroidEntryPoint 有一个值。您是否忘记应用 Gradle 插件?
- python - 将两个数据框保存在同一个 .csv 文件中
- flutter - 如何创建自定义后按按钮?
- adapter - 隔离主机名未显示在 FILE 适配器处理程序列表中