Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integration testing an ASP.NET MVC application

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

  • 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.

  • 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.

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

like image 489
Mosh Avatar asked Apr 13 '11 05:04

Mosh


2 Answers

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
  • 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.

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.

like image 57
Junior Mayhé Avatar answered Sep 27 '22 17:09

Junior Mayhé


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.

like image 42
ulu Avatar answered Sep 27 '22 16:09

ulu