Priority
Normal
Type
Bug 
State
Fixed 
Assignee
Alexey Kudravtsev 
Subsystem
Unit Testing. JUnit 
Affected versions
Fixed in
Fixed in build
Next build 
Build
6148
Fixed in build
8300
Severity
0
  • Submitted by   Gennadii Donchyts
    3 years ago (01 Feb 2007 21:09)
  • Updated by   root
    3 weeks ago (17 Jan 2010 19:41)
  • Jira: IDEA-36849
    (history, comments)

IDEA-36849

JUnit custom RunListener not called when using custom runner in @RunWith(MyRunner.class)

2
I'd like to setup custom output log file for each test in a separate file, to do this I've to detect test name each time tests are called.

My cusom runner:

{code:java}
package my.package;

import org.junit.internal.runners.InitializationError;
import org.junit.internal.runners.TestClassRunner;
import org.junit.runner.Description;
import org.junit.runner.Runner;
import org.junit.runner.notification.RunListener;
import org.junit.runner.notification.RunNotifier;

public class MyRunner extends TestClassRunner {
private static class MyListener extends RunListener {
@Override
public void testStarted(Description description) throws Exception { // <<<<<<<<<<< this method not called
System.err.println(" STARTED: " + description.getDisplayName());
}

@Override
public void testFinished(Description description) throws Exception {
System.err.println("FINISHED: " + description.getDisplayName());
}
}

public synchronized void run(final RunNotifier notifier) {
notifier.addListener(new MyListener()); // subscribe listener
super.run(notifier);
}

public MyRunner(Class<?> klass) throws InitializationError {
super(klass);
}

public MyRunner(Class<?> klass, Runner runner) throws InitializationError {
super(klass, runner);
}
}

My test:

{code:java}
package my.package;

import org.junit.*;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
import org.apache.log4j.Logger;

import java.io.File;

@RunWith(MyRunner.class)
public class MyTests {
    private Logger log = Logger.getLogger(MyTests.class);

    @Before
    public void setup()
    {
    }
    /**
     * Logging for each separate test should go into test.log file located in the test output folder  
     */
    @Test
    public void logging() {
        log.debug("test log message");
    }
}



JUnit 4.2 TestMethodRunner.java:

{code:java}
public void run() {
if (fTestIntrospector.isIgnored(fMethod)) {
fNotifier.fireTestIgnored(fDescription);
return;
}
fNotifier.fireTestStarted(fDescription); // <<<<<< this method does not work, probably source code is incorrect, can not debug inside
try {
long timeout= fTestIntrospector.getTimeout(fMethod);
if (timeout > 0)
runWithTimeout(timeout);
else
runMethod();
} finally {
fNotifier.fireTestFinished(fDescription);
}
}
{code}

When I debug JUnit in the method above stack trace shows that fNotifier is com.intellij.rt.junit4.Junit4TestMethodAdapter. Most probably it does not call super.fireXxx() because I can call listeners manually.

Environment: JUnit 4.1, JUnit 4.2

Issue was resolved
Comments (1)
 
History (1)
 
Links
 
Gennadii Donchyts
  Gennadii Donchyts
21 Jun 2007 18:24
(2 years ago)
#permalink
Comment about JUnit support in IntelliJ IDEA on Java.net http://weblogs.java.net/blog/fabianocruz/archive/2006/06/junit_4_you_1.html