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 {
  protected void runChild(FrameworkMethod method, RunNotifier notifier) {">>> Running " + method.getMethod().getDeclaringClass().getSimpleName() + "." + method.getName());
    super.runChild(method, notifier);"<<< End Run " + method.getMethod().getDeclaringClass().getSimpleName() + "." + method.getName() + "\n\n");

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: