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

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -