访问 SpecFlow Step Binding 类中的 TestContext
是否可以从 SpecFlow (1.7.1) 步骤绑定类中访问 MSTest TestContext? 在功能文件的生成代码中,有一个方法 FeatureSetup 它将 TestContext 作为参数,但显然没有对其执行任何操作。
Is it possible to access the MSTest TestContext from within a SpecFlow (1.7.1) step binding class?
In the generated code of a feature file there is a method FeatureSetup which takes the TestContext as an argument but apparently doesn't do anything with it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我找到了一种将参数传递给 TestContext 然后从 SpecFlow 访问它们的方法。
通过添加具有 TestContext 属性的 [TestClass] 并将其 AssemblyInit() 方法标记为 [AssemblyInitialize],以便在运行测试之前尽早初始化,并且 MSTest 将能够填充 TestContext。
然后可以从我的 BaseSteps 类访问它:
I found a way to pass parameters to TestContext and then access them from SpecFlow.
By adding a [TestClass] which has a TestContext property and marking its AssemblyInit() method as [AssemblyInitialize] so it gets initialized early before runnig the tests and MSTest will be able to populate the TestContext.
And then can access it from my BaseSteps class:
Gáspár Nagy 在 SpecFlow google 群组中回答:https://groups.google.com/group/specflow/browse_thread/thread/5b038e3e283fdbfe#
Gáspár Nagy answered on SpecFlow google group: https://groups.google.com/group/specflow/browse_thread/thread/5b038e3e283fdbfe#
进一步瓦伦丁的回答。以下是将添加到测试上下文中的测试生成器的示例 。它来自同一个 Google 群组。
Gáspár Nagy 表示,它可能会被添加到在 Specflow 中提供的提供商中。
因此,回答OP的问题,是的,这是可能的。
Further to Valentin's answer. Here is an example of a test generator that will add in the test context. Its from the same Google group.
Gáspár Nagy said it may be added to the provider that ships in specflow.
So to answer the OP's question, yes it is possible.