集成测试ASP.NET MVC应用程序

时间:2022-07-18 04:13:34

I need some advice about efficient way of writing integration tests for our current ASP.NET MVC application. Our architecture consists of:

我需要一些有关为当前ASP.NET MVC应用程序编写集成测试的有效方法的建议。我们的架构包括:

  • A Service Layer below Controllers
  • 控制器下面的服务层

  • Service Layer uses Repositories and Message Queue (sometimes) to send messages to external applications.
  • 服务层使用存储库和消息队列(有时)将消息发送到外部应用程序。

What I think should be done is to:

我认为应该做的是:

  • Write behavioral unit tests for all pieces in isolation. So, for example, we should unit test the Service Layer while mocking Repositories and Message Queues.

    单独编写所有部分的行为单元测试。因此,例如,我们应该在模拟存储库和消息队列时对服务层进行单元测试。

  • Same goes for Controllers. So we mock the Service Layer and unit test the Controller.

    控制器也是如此。所以我们模拟服务层并对Controller进行单元测试。

  • Finally, we write separate integration tests for Repositories against a real database and for Message Queue classes against real message queues to ensure they persist/retrieve data successfully.
  • 最后,我们针对真实数据库和针对真实消息队列的Message Queue类编写针对存储库的单独集成测试,以确保它们成功地持久保存/检索数据。

My Questions:

  • Are there any other types of integration tests that we need to write?

    我们需要编写其他类型的集成测试吗?

  • Do we still need to write integration tests for Services with the real Repositories and Message Queues?

    我们是否仍然需要使用真实的存储库和消息队列编写服务集成测试?

  • Do we still need to write integration tests for Controllers with the real Services (which in turn consists of real Repositories and Message Queues).

    我们是否仍然需要使用真实服务(实际的存储库和消息队列组成)为控制器编写集成测试。

Any advice would be greatly appreciated.

任何建议将不胜感激。

Cheers

3 个解决方案

#1


1  

Here at office we do not test against real services.

在办公室,我们不测试真实的服务。

  • We have test in service side
  • 我们在服务方面进行了测试

  • We are testing controllers as unit tests, we use mock in these unit tests
  • 我们测试控制器作为单元测试,我们在这些单元测试中使用mock

  • Yet we don't have a integration test :-(
  • 然而,我们没有集成测试:-(

We were advised to not use real services for testing, we use Rhino Mocks to simulate answers for methods being called inside controller actions.

我们被建议不要使用真实服务进行测试,我们使用Rhino Mocks来模拟控制器操作中调用方法的答案。

So the problem is still about how to do integration tests in a good way.

所以问题仍然是关于如何以良好的方式进行集成测试。

Maybe this could help you:

也许这可以帮助你:

http://www.codeproject.com/Articles/98373/Integration-testing-an-ASP-NET-MVC-application-wit.aspx

but I am still looking for a better understanding about its possibilities.

但我仍在寻找对其可能性的更好理解。

#2


1  

I'm using Ivonna for testing various levels of isolation. I'm able to test that a particular Url with some particular POST data hits the expected Action method with the expected arguments, and at the same time I'm able to stub/mock external services.

我正在使用Ivonna来测试各种级别的隔离。我能够测试具有某些特定POST数据的特定Url使用预期参数命中预期的Action方法,同时我能够存根/模拟外部服务。

#3


0  

I've been using SpecsFor.MVC for integration testing. Essentially you write code in a test class and the framework runs a browser interpreting your C# into browser actions. It's beautifully simple to use and setup.

我一直在使用SpecsFor.MVC进行集成测试。基本上,您在测试类中编写代码,框架运行浏览器将C#解释为浏览器操作。它的使用和设置非常简单。

#1


1  

Here at office we do not test against real services.

在办公室,我们不测试真实的服务。

  • We have test in service side
  • 我们在服务方面进行了测试

  • We are testing controllers as unit tests, we use mock in these unit tests
  • 我们测试控制器作为单元测试,我们在这些单元测试中使用mock

  • Yet we don't have a integration test :-(
  • 然而,我们没有集成测试:-(

We were advised to not use real services for testing, we use Rhino Mocks to simulate answers for methods being called inside controller actions.

我们被建议不要使用真实服务进行测试,我们使用Rhino Mocks来模拟控制器操作中调用方法的答案。

So the problem is still about how to do integration tests in a good way.

所以问题仍然是关于如何以良好的方式进行集成测试。

Maybe this could help you:

也许这可以帮助你:

http://www.codeproject.com/Articles/98373/Integration-testing-an-ASP-NET-MVC-application-wit.aspx

but I am still looking for a better understanding about its possibilities.

但我仍在寻找对其可能性的更好理解。

#2


1  

I'm using Ivonna for testing various levels of isolation. I'm able to test that a particular Url with some particular POST data hits the expected Action method with the expected arguments, and at the same time I'm able to stub/mock external services.

我正在使用Ivonna来测试各种级别的隔离。我能够测试具有某些特定POST数据的特定Url使用预期参数命中预期的Action方法,同时我能够存根/模拟外部服务。

#3


0  

I've been using SpecsFor.MVC for integration testing. Essentially you write code in a test class and the framework runs a browser interpreting your C# into browser actions. It's beautifully simple to use and setup.

我一直在使用SpecsFor.MVC进行集成测试。基本上,您在测试类中编写代码,框架运行浏览器将C#解释为浏览器操作。它的使用和设置非常简单。