Creating Dependencies Only to be able to Unit Test
Posted
by
arin
on Stack Overflow
See other posts from Stack Overflow
or by arin
Published on 2012-12-11T17:02:38Z
Indexed on
2012/12/11
17:03 UTC
Read the original article
Hit count: 410
I just created a Manager
that deals with a SuperClass
that is extended all over the code base and registered with some sort of SuperClassManager
(SCM
).
Now I would like to test my Manager
that is aware of only the SuperClass
. I tried to create a concrete SCM
, however, that depends on a third party library and therefore I failed to do that in my jUnit test. Now the option is to mock all instances of this SCM
.
All is good until now, however, when my Manager
deals with the SCM
, it returns children of the SuperClass
that my Manager
does not know or care about. Nevertheless, the identities of these children are vital for my tests (for equality, etc.).
Since I cannot use the concrete SCM
, I have to mock the results of calls to the appropriate functions of the SCM
, however, this means that my tests and therefore my Manager
need to know and care about the children of the SuperClass
.
Checking the code base, there does not seem to be a more appropriate location for my test (that already maintains the appropriate real dependencies).
Is it worth it to introduce unnecessary dependencies for the sake of unit testing?
© Stack Overflow or respective owner