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
Post a Comment