I did'nt find the answer for the above question, so sorry if it was already solved somewhere. As far as I could see, Mockito does not do that.
My question is how to mock/spy a class in which a private statis logger variable declared as follows:
class MyClassToMock {
private static AppLogger appLogger = UtilLogger.getLogger();
... other provate variables ad methods
}
Thank you in advance;
--
You received this message because you are subscribed to the Google Groups "mockito" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mockito+u...@googlegroups.com.
To post to this group, send email to moc...@googlegroups.com.
Visit this group at http://groups.google.com/group/mockito?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
--
Of course, as the guys from GOOS would say, if your logging is important, then you probably need to extract it into a separate class that you own, which makes it more obvious that you need to test interactions.
Some instances when I might want to test things are logged
the spec calls for specific entries to appear in the log for automatic monitoring purposes.
when something goes wrong because of a data error – to check a reference/item identifier is written to log so support can go straight to the item and look for the data error rather than having to check all items in batch/waiting to be processed.
Other than specific requirements I think you should generally ignore logging in unit tests (other than to make sure each log call is run on unit tests – especially if using something like String.format to build error messages) - One irritation I recall is someone using JMock (IIRC) religiously checking what logging was happening and the framework throwing an error if you accessed it more times than defined – a pita when you wanted to add extra information during testing to see what was happening (didn't take long to allow all)