C# 哪些行为驱动开发 (BDD) 工具/框架可用于 Microsoft Stack?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8922079/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What Behavior Driven Development (BDD) Tooling/Frameworks are available for the Microsoft Stack?
提问by one.beat.consumer
I am interested in Behavior Driven Development (BDD)
我对行为驱动开发 (BDD)感兴趣
Are there any good frameworks and/or tooling available for the .Net platform (preferably C# and ASP.Net)?
.Net 平台(最好是 C# 和 ASP.Net)是否有任何好的框架和/或工具可用?
And when has BDD proved most appropriate to use in real world scenarios? (auxiliary question)
什么时候证明 BDD 最适合在实际场景中使用?(辅助问题)
采纳答案by Haris Hasan
On googling I found Behavior Driven Development (BDD) with SpecFlow and ASP.NET MVC. You might find it useful, take a look. Also go through Behavior-Driven Development with SpecFlow and WatiN
在谷歌搜索中,我发现了 SpecFlow 和 ASP.NET MVC 的行为驱动开发 (BDD)。你可能会觉得它很有用,看看吧。还可以使用 SpecFlow 和 WatiN进行行为驱动开发
A nice presentation on Pros and Cons of BDD
关于BDD 的利弊的精彩介绍
A channel 9 video Behavior-Driven Development in the Real World
and last but not least an InfoQ article Behavior Driven Development In .NET
最后但并非最不重要的一篇 InfoQ 文章.NET 中的行为驱动开发
回答by Be.St.
Also MSpecis a good framework.
此外MSpec是一个很好的框架。
I use it in the Microsoft stack you mention (C#, ASP.Net and MVC) and I like his syntax.
我在您提到的 Microsoft 堆栈(C#、ASP.Net 和 MVC)中使用它,我喜欢他的语法。
BDD helps you thinking in business/feature oriented way not just in a code way. So you are most focused on business value.
BDD 可以帮助您以面向业务/功能的方式进行思考,而不仅仅是以代码方式进行思考。所以你最关注商业价值。
It also helps in user acceptance test to create a trust between you and customer.
它还有助于用户验收测试,以在您和客户之间建立信任。
回答by Maksim Gladkov
回答by Lunivore
+1 for people's recommendation of SpecFlow for scenarios; never used it but heard many good things about it. I've been using plain old NUnit with a little DSL like this. MSTest would work similarly.
+1 人们对 SpecFlow 的场景推荐;从未使用过它,但听说过很多关于它的好东西。我一直在使用普通的旧 NUnit 和像这样的一点 DSL 。MSTest 的工作方式类似。
You canalso do BDD in the unit space, which is what MSpec is designed to do. I'm personally hating MSpec, but the rest of the team here love it. They like writing examples of how the code works. I like to show why the behavior is valuable. It's a subtle distinction and if you're not worried about doing this at a unit level it won't hit you.
你也可以在单位空间中做 BDD,这也是 MSpec 的设计目的。我个人讨厌 MSpec,但这里的其他团队成员喜欢它。他们喜欢编写代码如何工作的示例。我喜欢展示为什么这种行为是有价值的。这是一个微妙的区别,如果您不担心在单元级别执行此操作,它不会影响您。
Other frameworks to look at include Concordion, Fitnesse.NET (please put FitSharp behind it!) and TickSpec.
其他需要查看的框架包括 Concordion、Fitnesse.NET(请把 FitSharp 放在后面!)和 TickSpec。
In the real world, the most valuable bit of BDD by a long way is the conversations, not the automated tests. Here's a couple of quick hints and tips for making it work:
在现实世界中,BDD 最有价值的一点是对话,而不是自动化测试。以下是一些使其工作的快速提示和技巧:
Don't write automated tests over things which are in flux. It just commits you to stuff you got wrong. Wait until the UI has settled a bit then do it.
If you don't care much about your UI, but do care about data integrity, write the scenarios over the controller / presenter layer (eg: for admin screens).
Don't start with login. Start by describing a valuable part of the application for which you might log in. Do that first (assume you only have one user). You'll get quicker feedback on the risky bits.
Seek quick feedback on the risky bits, which will usually be the bits which you've never done before. Use scenarios to have conversations around them. Write anything interesting you discover down, but forget the scenarios which are obvious - they're obvious! Don't worry about automating them to start with. Having conversations is more important than writing down conversations is more important than automating conversations.
不要对不断变化的事物编写自动化测试。它只会让你犯错。等到 UI 稳定下来然后再做。
如果您不太关心您的 UI,但确实关心数据完整性,请在控制器/展示器层上编写场景(例如:用于管理屏幕)。
不要从登录开始。首先描述您可能登录的应用程序的一个有价值的部分。首先这样做(假设您只有一个用户)。您将更快地获得有关风险部分的反馈。
寻求对风险部分的快速反馈,这通常是您以前从未做过的部分。使用场景围绕它们进行对话。写下你发现的任何有趣的东西,但忘记那些显而易见的场景——它们是显而易见的!不要担心自动化它们开始。进行对话比写下对话更重要比自动对话更重要。
Good luck! If you want to know more about BDD, I put together a page of relevant links here.
祝你好运!如果你想了解更多关于 BDD 的信息,我在这里整理了一个相关链接的页面。
回答by user3632158
One interesting BDD frameworks is Concordion.NET. It is an open source BDD framework for the Microsoft stack that uses NUnit to execute the Concordion.NET tests: https://github.com/concordion/concordion-netAs Concordion specifications are written in simple HTML, it provides a good basis for a living documentation system. You can use a what-you-see-is-what-you-get (WYSIWYG) editor like BlueGriffon to describe your intended behavior of your software in simple HTML documents and instrument them to verify your system under test. According to the excellent classification of BDD tools, Concordion.NET focuses on business readable input (and reaches business readable output as well). It moves even beyond BDD and supports ATDD: http://assertselenium.com/2012/11/05/difference-between-tdd-bdd-atdd/
一个有趣的 BDD 框架是Concordion.NET。它是 Microsoft 堆栈的开源 BDD 框架,使用 NUnit 执行 Concordion.NET 测试:https: //github.com/concordion/concordion-net由于 Concordion 规范是用简单的 HTML 编写的,因此它为一个活文件系统。您可以使用 BlueGriffon 之类的所见即所得 (WYSIWYG) 编辑器在简单的 HTML 文档中描述软件的预期行为,并检测它们以验证您的被测系统。根据BDD 工具的优秀分类,Concordion.NET 专注于业务可读输入(并达到业务可读输出)。它甚至超越了 BDD 并支持 ATDD:http://assertselenium.com/2012/11/05/difference-between-tdd-bdd-atdd/
回答by Dennis Jurgensen
Spec4Net (https://bitbucket.org/fthomsen/spec4net/) is a nice framework too. We use it extensively at work. The learning curve is almost non-existing and the natural flow seems intuitive.
Spec4Net ( https://bitbucket.org/fthomsen/spec4net/) 也是一个不错的框架。我们在工作中广泛使用它。学习曲线几乎不存在,自然流程似乎很直观。
回答by Wojciech Kotlarski
LightBDDis an open source framework allowing to write BDD tests that are easy to read but also easy to maintain and extend when project grows larger.
LightBDD是一个开源框架,允许编写易于阅读的 BDD 测试,但在项目变大时也易于维护和扩展。
The main features that it offers are:
它提供的主要功能是:
- easy to read scenarios,
- easy maintenance of tests,
- integration with well known testing frameworks (NUnit/ MbUnit/ MsTest/ xUnit),
- scenario steps execution tracking and execution time measurement,
- test execution summary report generation in HTML (an example report), XML and plain text format.
- 易于阅读的场景,
- 易于维护测试,
- 与众所周知的测试框架(NUnit/ MbUnit/ MsTest/ xUnit)集成,
- 场景步骤执行跟踪和执行时间测量,
- 以 HTML(示例报告)、XML 和纯文本格式生成测试执行摘要报告。
It bases on tests that are written purely in code, which means native support for refactoring, code analysis, test running and all other features that Visual Studio / Intellisense / Resharper offers.
它基于完全用代码编写的测试,这意味着对重构、代码分析、测试运行和 Visual Studio/Intellisense/Resharper 提供的所有其他功能的本机支持。
An example test written in this framework looks as follows:
在此框架中编写的示例测试如下所示:
[TestFixture]
[FeatureDescription(
@"In order to access personal data
As an user
I want to login into system")] //feature description
[Label("Story-1")]
public partial class Login_feature //feature name
{
[Test]
[Label("Ticket-1")]
public void Successful_login() //scenario name
{
Runner.RunScenario(
Given_user_is_about_to_login, //steps
Given_user_entered_valid_login,
Given_user_entered_valid_password,
When_user_clicked_login_button,
Then_login_is_successful,
Then_welcome_message_is_returned_containing_user_name);
}
}
More information about framework could be found on project wiki pageand project main page.
有关框架的更多信息可以在项目 wiki 页面和项目主页上找到。

