我已将Specflow从3.0.225
更新为3.1.62
,并收到错误Tests_Integration_MSTestAssemblyHooks: Cannot define more than one method with the AssemblyInitialize attribute inside an assembly.
原因显然是我在项目中已经拥有[AssemblyInitialize]
属性。我该如何解决?
答案 0 :(得分:0)
原因是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()
{
// ...
}
}