java - How to write test cases for private void methods using junit and mockito -


this question has answer here:

can write test cases setaddr() method, because private void method, can 1 please me?

class wcfg  {  private void setaddr(cfg cfg, string... arg)          throws exception { try {  } catch (exception e) {   throw new exception("invalid ip address.", e); } }  public string process(string... arg) throws exception {   mcfg mcfg = new mcfg();    try {     setaddr(mcfg, arg);    } catch (exception e) {     return "wrong argument format.";   }   cfg.write();    return "success";  } } 

every private method call in of public or accessible method directly or in directly. so, no need write case them.

then if want write test case use :

deencapsulation.invoke(someclasswhereprivatemethod.class, "methodname", argument1, argument2, argument3); 

here deencapsulation mockit.deencapsulation.

you can download jar here.


Comments

Popular posts from this blog

'hasOwnProperty' in javascript -

python - ValueError: No axis named 1 for object type <class 'pandas.core.series.Series'> -

java - How to provide dependency injections in Eclipse RCP 3.x? -