How to verify that error was logged with unit tests
问题 Let's say I have the following class like this: public class MyClass { public static final Logger LOG = Logger.getLogger(MyClass.class); public void myMethod(String condition) { if (condition.equals("terrible")) { LOG.error("This is terrible!"); return; } //rest of logic in method } } My unit test for MyClass looks something like this: @Test public void testTerribleCase() throws ModuleException { myMethod("terrible"); //Log should contain "This is terrible!" or assert that error was logged }