java - Junit testing correct log output from method? -
this question has answer here:
i have following simple method
within java
application:
method wish test:
public void showoutputofidentifications(int age) { if(age>25){ logger.info("over 25"); }else{ logger.info("25 or under"); } }
how can test method ensure logging should if value over/under 25?
for reference: using junit
framework mockito
. logger slf4j
.
provided logger object, classic way replace mock. mockito known mock library, other around, pick one. mockito, like:
logger_mock = mock(loggerclass.class); // inject logger_mock class test, use reflection change // private attribute classtotest.showoutputofidentifications(10); verify(logger_mock).info("25 or under");
Comments
Post a Comment