java - How to mock a class in another class junit mockito -
following 2 classes defined as:
class1{ public method1 { class2.getinstance().method2(); } } class2{ public static getinstance() { .... } public method2() { .... } public class3 obj = new class3(); }
i need write junit test method1 of class1. need know how can mock getinstance() , method2() of class2.
also, please tell me how can mock object of class3.
if find hard write test class, should redesign class better testability, that's reason tdd called test driven design. should never difficult write test simple class.
however,
- how mock static methods described here powermockito mock single static method , return object (thanks jorge)
- how partially mock class described here: how mock call of inner method junit
Comments
Post a Comment