I have a set of classes that have dependencies at instantiation, i.e. when creating an object of type A, it also creates another type B, which subsequently creates other types of C, etc.
For testing, I don’t need all the functionality of all levels to check the top ones, so I can use stubs or mocks, but since I have one explicit newin the constructors, I don’t see a direct path other than changing the code to use AbstractFactory and ensuring that it creates fakes during testing.
So, is there a way of “black magic” to crack the loader of Java classes to create fake test classes instead of the usual ones when creating objects with new?
Thank!
source
share