问题描述
我有2个功能,使用一个共同的'如果'的一步,但在不同的类别不同的然后的步骤。
I have 2 features that use a common 'When' step but have different 'Then' steps in different classes.
我如何进入,例如, ?从我的两人随后步当步我的MVC控制器调用的ActionResult
How do I access, for example, the ActionResult from my MVC controller call in the When step in my two Then steps?
推荐答案
在SpecFlow 1.3有三种方法:
In SpecFlow 1.3 there are three methods:
- 静态成员
- ScenarioContext
- ContextInjection
评论:
-
静态成员非常务实,在这种情况下没有那么邪恶,因为我们的开发人员可能会首先想到(没有穿线或需要嘲讽/升压型定义替换)
static members are very pragmatic and in this case not so evil as we as developers might first think (there is no threading or need for mocking/replacing in step-definitions)
看到@Si答案请这个线程
See answer from @Si Keep in this thread
如果一步定义类的构造函数需要参数,Specflow试图注入这些参数。这可以用来注入相同的上下文分成几个步骤,定义。
这里见一个例子:
If the constructor of a step definition class needs arguments, Specflow tries to inject these arguments. This can be used to inject the same context into several step-definitions.
See an example here: https://github.com/techtalk/SpecFlow/wiki/Context-Injection
这篇关于在SpecFlow我怎么能分享步骤/功能之间的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!