在SpecFlow我怎么能分享步骤/功能之间的数据? [英] In SpecFlow how can I share data between steps/features?

查看:599
本文介绍了在SpecFlow我怎么能分享步骤/功能之间的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有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:


  1. 静态成员

  2. ScenarioContext

  3. ContextInjection

评论:


  1. 静态成员非常务实,在这种情况下没有那么邪恶,因为我们的开发人员可能会首先想到(没有穿线或需要嘲讽/升压型定义替换)

  1. 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试图注入这些参数。这可以用来注入相同的上下文分成几个步骤,定义。

这里见一个例子:
https://开头github.com/techtalk/SpecFlow/wiki/Context-Injection

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我怎么能分享步骤/功能之间的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆