Monthly Archives: November, 2014

Separate JUnit`s log-output per testcase

Note to self:
When lost in the log of a TestSuite, this simple example of a JUnit Runner may help.

package com.thyssenkrupp.tkse.qbic.tests.runner;
import org.apache.log4j.Logger;
import org.junit.runner.notification.RunNotifier;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.model.FrameworkMethod;
import org.junit.runners.model.InitializationError;
public class LoggingBlockJUnit4ClassRunner extends BlockJUnit4ClassRunner {
  private static final Logger LOG = Logger.getLogger(LoggingBlockJUnit4ClassRunner.class);
  public LoggingBlockJUnit4ClassRunner(Class< ? > klass) throws InitializationError {
    super(klass);
  }
  @Override
  protected void runChild(FrameworkMethod method, RunNotifier notifier) {
    LOG.info(">>> Running " + method.getMethod().getDeclaringClass().getSimpleName() + "." + method.getName());
    super.runChild(method, notifier);
    LOG.info("<<< End Run " + method.getMethod().getDeclaringClass().getSimpleName() + "." + method.getName() + "\n\n");
  }
}