Disable logger during unit testing?

Is it possible to disable log execution during testing?

I have this class

public class UnitTestMe {

    private final MockMe mockMe;
    private final SomethingElse something;

    private final Logger logger = LoggerFactory.getLogger(this.getClass().getClass());

    public UnitTestMe(MockMe mockMe, SomethingElse something) {
        this..
    }

    public toTest() {
        logger.info("Executing toTest. MockMe a: {}, Foo: b: {}", mockMe.toString(), something.foo().bar());
        mockMe.execute();
    }
}

My Unit Test does not work with NullPointerException because something.foo () is not a mocked object (I use mockito with nicemock).

How can I test this class without deleting the log statement and without taunting the irrelevant parts of the type dependencies something?

Edit: something in this case is a client object that is not used in a function toTest(), but is needed in other parts of this class. I use the Customer class in a logger statement to associate an action with a user.

2: ? , NullPointerException, `something' .

+5
3

: WARN ERROR . isInfoEnabled():

if(logger.isInfoEnabled())
    logger.info("Executing toTest. MockMe a: {}, Foo: b: {}", mockMe.toString(), something.foo().bar());

: , - , , toTest(), . , , , . SomethingElse .

+3

something. , foo(), , .

+2

try catch NullPointerException.

NullPointerException, NullPointerException

@expect(NullPointerException.class)
public void testMethod() {
//your test method logic
}
0

All Articles