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

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -