When writing some Unit-tests I found out, that we use a lot of static method-calls from Utility-classes. Now with Mockito I can't mock the calls of them. So what would be the best approach?
I know wrote public methods, inside the class where I just return the static call. For example:
public String getName(File file){ return PDFUtil.getName(file); }
And then I call the public method inside the other method. And now I can mock the getName() method with Mockito with Spying.
However two things:
1.) There's redundancy. I maybe use the PDFUtil.getName(File) method in other classes too, so I should only have one class and should only implement getName() once.
2.) Let's consider I have like 4 different static method calls and extract them in 4 different methods. These are now methods I can't test. So is this ok, since it's said very easy methods like getters and setters shouldn't be tested?
Aucun commentaire:
Enregistrer un commentaire