I have something as,
classB { classA a = new classA(); ... } classA { ... } I would like to write junit on classB. How to mock object a of classA?
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about CollectivesStack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
Explore Stack InternalI have something as,
classB { classA a = new classA(); ... } classA { ... } I would like to write junit on classB. How to mock object a of classA?
Pass the A in as a parameter to the constructor of B.
Explore related questions
See similar questions with these tags.
AwithinB's constructor and instead use Inversion of Control to pass an instance ofAtoB's constructor. The only other way that comes to my mind is using powermock, but this messes with the bytecode and thus cann screw up JaCoCo Code coverage.