Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integration tests implementation

I have a three tiered app

  • web app (asp.net mvc for simplicity here),
  • business services
  • data repositories

And I know there are four types of integration tests:

  • top down
  • bottom up
  • sandwich (combination of the top two)
  • big bang

I know I would write big-bang tests just like unit tests but without any mocking so I would employ a backend DB as well...

Questions

I don't know how to write other types of integration tests?

  1. How do I write non-bigbang types of integration tests?
  2. Should integration tests be equal to unit tests meaning same number of tests, but testing without mocks? Or should these tests test something completely different?

Could anybody provide any information how to do this (if at all) or whether it's actually feasible doing it?

like image 350
Robert Koritnik Avatar asked Sep 30 '10 13:09

Robert Koritnik


1 Answers

I suggest doing these:

  1. unit tests / must not hit any external resource
  2. focused integration tests (I guess that'd be bottom up). You should have code that is very close to the external resource, and the sole responsibility of it is integrating with it. Don't try to unit test those classes, instead do very focused tests that hit the real resource and don't have to deal with the rest of the logic in your system. Keep this integration classes as thin as possible
  3. full system tests (I guess big bang). I mean with the UI and everything (or API if that's your endpoint). Make sure you cover as much as possible with the previous tests, and this is more like simple checks the underlying pieces are hooked appropriately.

Depending on your system, you may or not want to complement 3 with integration tests at the top level of the code, but without involving the UI. Regardless of which option you take, make sure to have more comprehensive coverage through unit & focused integration tests, as testing various behavior at the top level have a complexity level that can get out of control very quickly.

Should integration tests be equal to unit tests meaning same number of tests, but testing without mocks? Or should these tests test something completely different?

As I mentioned in 1 & 2, its best when those test different things. This depends on the system, but I'd usually expect the amount of unit tests to be a few times the amount of integration tests. For full system tests, make sure you have enough so that you can tell all the pieces were hooked correctly, but not so much that it becomes too complex to test each scenario.

like image 187
eglasius Avatar answered Oct 30 '22 05:10

eglasius