How do I do unit & integration testing in a BDD style in ASP.NET MVC?

后端 未结 2 2055
难免孤独
难免孤独 2021-02-08 08:11

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: individua

2条回答
  •  醉酒成梦
    2021-02-08 08:18

    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.

    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 <-- For BDD SpecFlow tests.

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

    MyProject.Tests.Unit

    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.

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

提交回复
热议问题