Reputation: 3333
I have a static void method from a different class that is invoked along my code as some sort of logger. In order to automatically test the different use cases of my code I was thinking of checking the logs of the system created by such method.
What I thought is to mock that class and overwrite the behaviour of the method so that it outputs to System.err
. Also, redirecting System.err
as explained here so that I can easily verify the correct functioning of the code.
I do not know how to override the standard behaviour of the method so that it does something (printing to the stderr) instead of what it normally does (by not mocking it) or nothing (what I get my using when(...).thenReturn(...)
)
Upvotes: 1
Views: 253
Reputation: 10586
Mocking static method is not a good way to go, believe me.
Altough it is possible with for example PowerMock
framework (it is going to replace class loader under the hood), but still it is discouraged.
Upvotes: 4