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

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

javascript - Confirm a form & display message if form is valid with JQuery -

ionic framework - Meteor - Error: Failed to execute 'insertBefore' on 'Node' -