Suppose we have a hierarchy like the following, where each thing under it means it is composed of that type:
CarCompany
|
CarFactory
|
Car
|
Engine
|
+------+-----+
| | |
PartA PartB PartC
For everything above, also assume each component has logic associated with it and it's not just a glorified collection. As such, a CarCompany
owns many CaryFactory
s, which in turn makes multiple Car
s, which have their own possible Engine
types, and those are made up of atomic Part
s.
Now suppose that we have interfaces used for each step, like:
CarCompany
adds new factories with aCarFactory
interfacesCarFactory
adds cars by aCar
interface- A
Car
adds its engine by anEngine
interface
As such, this makes unit testing easier since we can mock the interfaces and make sure the logic works without spending forever instantiating stuff.
When it comes to integration testing however, we want to make sure everything works as intended... but at what level do we do integration testing? Do we do a bunch of integration tests at the top level? Or do we do one for each level that accepts an interface?
Reason I'm asking is because integration testing is suppose to make sure our classes integrate together by definition, which means wherever we have an interface we want to test with concrete instances. However this implies that we would do testing at N - 1
levels for N
levels, since the bottom level does not need to be tested. Is this overkill though? Or should integration testing only be done at the top level?