适用于单元测试的SpecFlow/BDD? [英] SpecFlow/BDD for Unit Tests?
问题描述
似乎互联网没有明确的答案,也没有一套原则可以帮助我回答问题.因此,我在SO上向伟大的人们求助,以帮助我找到答案或指导思想:)
Seems like the internet doesn't have a definitive answer, or set of principles to help me answer the question. So I turn to the great folk on SO to help me find answers or guiding thoughts :)
SpecFlow对于.NET中的BDD非常有用.但是,当我们谈论BDD时,我们只是在谈论集成/验收测试,还是在谈论单元测试-完全替代TDD?
SpecFlow is very useful for BDD in .NET. But when we talk about BDD are we just talking integration/acceptance tests, or are we also talking unit tests - a total replacement for TDD?
我只在小型项目中使用过它,但我发现即使对于单元测试,SpecFlow仍可以改善代码文档和语言方面的思考. Converseley,我看不到一个地方的完整测试代码,因为这些步骤是分散的.
I've only used it on small projects, but I find that even for my unit tests, SpecFlow improves code documentation and thinking in terms of language. Converseley, I can't see the full code for a test in one place - as the steps are fragmented.
现在是您.......
Now to you..........
我忘了提到我在RoR社区中看到了RSpec,该社区使用BDD样式的语法进行单元测试.
I forgot to mention that I see RSpec in the RoR community which uses BDD-style syntax for unit testing.
推荐答案
我最近开始使用 SpecFlow
进行BDD测试,但我仍然使用单元测试和集成测试.
I've recently started to use SpecFlow
for my BDD testing, but also, I still use unit and integration tests.
基本上,我将测试分为单独的项目:
Basically, I split the tests into seperate projects:
- 规格
- 集成
- 单位
我的单元测试用于测试单个方法,不执行任何数据库调用或任何外部引用.我对单个方法调用(可能有时是两个)使用集成测试,这些方法确实与外部资源(例如数据库或Web服务等)进行交互.
My unit tests are for testing a single method and do not perform any database calls, or external references whatsoever. I use integration tests for single method calls (maybe sometime two) which do interact with an external resources, such as a database, or web service, etc.
我使用BDD描述模拟项目业务/领域要求的测试.例如,我将为一个项目的发票生成功能制定规范.或与购物篮一起使用.这些测试遵循
I use BDD to describe tests which mimick the business/domain requirements of the project. For example, I would have specs for the invoice generation feature of a project; or for working with a shopping basket. These tests follow the
我想作为用户,
As a user, I want, In order to
语义类型.
我的建议是根据需要拆分测试.避免尝试使用SpecFlow执行单元测试.
My advise is to split your tests based on your needs. Avoid trying to perform unit testing using SpecFlow.
这篇关于适用于单元测试的SpecFlow/BDD?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!