java - Mockito mock testing for nested functions calls -


i have serious conceptual problem mock testing in scenario of nested function calls. i'm using junit , mockito in project. let me explain problem following example:-

public class classa {         public void methodone(param1, param2, param3, param4) {             //              string temp = methodtwo(param2, param3, param4);              //         }          public string methodtwo(param2, param3, param4) {             //              return methodthree(param2, param3) + methodfour(param4);         }          public string methodthree(param2, param3) {             //             return param2.get(0).getindex + ":" + param3.getposition();         }          public string methodfour(param4) {             //              return param4.getdetail() + "|" + param4.getcount();         }     } 

if have test basic methods methodthree() , methodfour(), can create mocks of required params required stubbing (to support executtion of function being tested) , execution , verification (state/behavior) there after.

but methods methodtwo(), having nested calls other functions have been tested separate unit. if pass mock objects methodtwo(), passed nested methods , give nullpointerexception() these mocks not stubbed per need of nested function calls. surely, can add stubbing mocks support smooth execution in nested calls too, not healthy approach. burden of stubbing aggravate further move large methods methodone() or other.

as far unit testing concerned, don't care other units beside 1 being tested. please guide me being wrong , suggest better/proper way of unit , mock testing. thanks.

my thought here methodone , methodtwo each meet kind of specification, in terms of behaviour should have. fact chose implement each of these via calls other methods of same class irrelevant; should test behaviour correct. don't @ implementation when write test - instead, @ specification.

of course, if choose ignore advice, can use mockito spy, , stub out methods while test others. seriously, don't.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

android - Inheriting from Theme.AppCompat* -