1

我目前正在用 C# 编程,我正在使用 Visual Studio 2010、.Net 4、SpecFlow、NUnit,我很好奇 SpecFlow 是否有办法为我的 *.feature 文件自动生成 *StepDefintion.cs。目前我必须将生成的代码复制并粘贴到一个新的“SpecFlow 步骤定义”文件中。

如果有人知道这是否可能,以及如何做到这一点,那就太好了!

4

2 回答 2

3

最新版本的 SpecFlow 在 IDE 集成中具有此功能。

Select “Generate Step Definitions” from the context menu of the feature file and the appearing dialog will guide you how to create a new binding class with the step definitions for the selected unbound steps. You don’t have to care about parameters: the most common parameter usage patterns (quotes, apostrophes, numbers) are detected. You can also choose from different step definition styles, including the new regex-less formats (see below).

在此处输入图像描述

http://www.specflow.org/specflownew/WhatsNew19.html

于 2013-04-21T19:39:03.963 回答
2

不是开箱即用。有一个关于使用 nUnit 并在步骤中使代码变得粗略的教程,但是我没有在我们的项目中使用 SpecFlow 足够长的时间来确定它在哪里生成这个存根代码。稍微搜索一下应该可以找到答案。在最坏的情况下,找到 SpecFlow 和 nUnit 的教程以及在 nUnit 中生成的代码(非常简洁的东西,虽然不是自动化的)。

我在某处开始编写一些代码来创建存根文件,但不使用 SpecFlow 的决定让我远离了这个方向(再也无法证明时间的合理性)。我以为我写了博客,但搜索我的博客后发现 nada(旁白:你可以在 site:gregorybeamer.wordpress.com 找到 SpecFlow,但它是一般的“单元测试”帖子)。

我曾考虑过贡献代码,但考虑到我现在没有空闲时间来贡献开源代码,不同可能性的数量让我头晕目眩。;-)

于 2011-06-08T20:21:02.377 回答