Java – the value passed by the unit test to the static method
Example code:
class MyClass { public void myMethod(Request request) { Item item = getItem(); ItemUtilHelper.setCertainProperties(newProperty,item); differentClass.staticMethod(item); } }
Itemutilhelper already has a unit test class to verify that the item is updated correctly
How do I perform unit tests and call differentclass with updated item parameters staticMethod?
Solution
First, let me say that static methods themselves are code smells Mi š ko Hevery summed up it quite nicely by saying:
If you only want to use mockito, your problem cannot be solved:
(see mockito FAQ)
You can use powermock to achieve your goals Note, however, that powermock runs at the bytecode level That means
>You may not have tested the exact same bytecode you use in production (such as heisenbugs) and > which can be tightened with other tools, such as jacoco
If you still want to continue, you are looking for a spy You can find a tutorial on powermock's wiki Although not directly related, the answer to this question provides some other examples of how to create a spy for a class The entire example can be found in automation Rhapsody