我该怎么做单元放大器;在ASP.NET MVC BDD的风格的集成测试? [英] How do I do unit & integration testing in a BDD style in ASP.NET MVC?

查看:153
本文介绍了我该怎么做单元放大器;在ASP.NET MVC BDD的风格的集成测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我学习行为驱动开发与ASP.NET MVC和的基础上,<一href=\"http://blog.stevensanderson.com/2010/03/03/behavior-driven-development-bdd-with-specflow-and-aspnet-mvc/\"相对=nofollow>从史蒂夫·桑德森后,了解BDD可以说,至少,以下测试类型:code和个别单位; UI交互。类似的事情在这个帖子提及。我需要两个不同的测试框架,如果我想这两个单元测试和集成测试?

I am learning Behavior Driven Development with ASP.NET MVC and, based on a post from Steve Sanderson, understand that BDD can mean, at least, the following test types: individual units of code & UI interactions. Something similar is mentioned in this post. Do I need two different test frameworks if I want both unit and integration testing?


  • 单元测试库,控制器,和放大器;使用上下文/规范的框架,像MSpec服务。测试这个结果将是开发团队很有用。

  • Unit testing repositories, controllers, & services using a context/specification framework, like MSpec. The results of testing with this will be useful to the development team.

测试完整的行为,使用给定/时/然后框架,像SpecFlow与华廷(集成)。这个测试的结果将是为我的客户非常有用。

Testing complete behaviors (integration) using a given/when/then framework, like SpecFlow with Watin. The results of this testing will be useful for my client.

到目前为止,我已经看到了使用BDD的视频只限于测试实体的行为,而测试库,控制器等的行为......有一个示例项目,我可以看到两个自动化单元测试和集成使用BDD的方法测试?

The videos I have seen so far on using BDD have only been limited to testing the behaviour of entities without testing the behaviour of repositories, controllers, etc... Is there a sample project where I can see both automated Unit and Integration testing using a BDD approach?

推荐答案

我个人使用SpecFlow构建功能特定的测试(即用户创造了新的记录公司),在那里我有时会(但不总是)使用华廷。为了测试我的respositories或服务类,我将使用单位/集成测试与NUnit的。集成测试是当我需要在测试过程中交谈的数据库,单位是当我简单地运行在目标对象code测试,无需外部的互动。

Personally I use SpecFlow for building feature specific tests (i.e. "User creates new company record") where I'll sometimes (but not always) use Watin. For testing my respositories, or service classes, I'll use unit/integration tests with NUnit. Integration tests are for when I need to talk to the database during the test, unit is for when I simply run code in the target object under test without external interactions.

我要说的是,你不需要使用BDD框架,用于非UI测试。你可以,如果你想要的,但没有硬性规定这一点。如果你要做到这一点,那么我强烈建议为您创造更多的测试,然后一个项目。保持他们分裂是一个好主意,而不是混合所有的测试到一个项目中。你可以为它们命名:

I would say that you don't need to use a BDD framework for your non UI tests. You can if you want, but there is no hard and fast rule on this. If you are going to do this, then I highly recommend creating more then one project for your tests. Keeping them split is a good idea, rather then mixing all the test into one project. You could name them:

&MyProject.Tests.Features LT; - 对于BDD
  SpecFlow测试。

MyProject.Tests.Features <-- For BDD SpecFlow tests.

MyProject.Tests.Integration&下; - 对于
  一个存取测试
  外部资源即数据库。

MyProject.Tests.Integration <-- For tests that access an external resource i.e. database.

MyProject.Tests.Unit

MyProject.Tests.Unit

如果你不想使用两个BDD框架,您仍然可以使用MSTest的/ NUnit的一个BDD的方式。例如,博客文章中介绍了一个很好的命名约定,接近BDD,但目的在MSTest的/ NUnit的单元测试。您可以使用此为您的非SpecFlow测试时,您的测试之类的东西仓库。

If you're not wanting to use two BDD frameworks, you can still use MSTest/NUnit in a BDD way. For example, this blog article describes a nice naming convention which is close to BDD, but aimed at MSTest/NUnit unit tests. You could use this for your non SpecFlow tests when your testing things like repositories.

在总结 - 你不必使用SpecFlow和MSpec在您的测试,但如果这样做,那么我建议单独的测试项目

In summary - you don't have to use SpecFlow and MSpec in your testing, but if you do, then I recommend separate test projects.

这篇关于我该怎么做单元放大器;在ASP.NET MVC BDD的风格的集成测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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