Skip to content

Commit

Permalink
Call methodBlock() after fireTestStarted() (junit-team#1463)
Browse files Browse the repository at this point in the history
  • Loading branch information
panchenko authored and kcooney committed Jun 8, 2017
1 parent 563d32c commit 3f736cf
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 8 deletions.
13 changes: 6 additions & 7 deletions src/main/java/org/junit/runners/BlockJUnit4ClassRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,12 @@ protected void runChild(final FrameworkMethod method, RunNotifier notifier) {
if (isIgnored(method)) {
notifier.fireTestIgnored(description);
} else {
Statement statement;
try {
statement = methodBlock(method);
}
catch (Throwable ex) {
statement = new Fail(ex);
}
Statement statement = new Statement() {
@Override
public void evaluate() throws Throwable {
methodBlock(method).evaluate();
}
};
runLeaf(statement, description, notifier);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import java.util.List;

import org.junit.Test;
import org.junit.runner.Description;
import org.junit.runner.JUnitCore;
import org.junit.runner.notification.RunListener;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.model.InitializationError;

Expand All @@ -30,4 +33,36 @@ public void detectNonStaticEnclosedClass() throws Exception {
causes.get(0).getMessage());
}
}
}

private static String log;

public static class MethodBlockAfterFireTestStarted {
public MethodBlockAfterFireTestStarted() {
log += " init";
}

@Test
public void test() {
log += " test";
}
}

@Test
public void methodBlockAfterFireTestStarted() {
log = "";
JUnitCore junit = new JUnitCore();
junit.addListener(new RunListener() {
@Override
public void testStarted(Description description) throws Exception {
log += " testStarted(" + description.getMethodName() + ")";
}

@Override
public void testFinished(Description description) throws Exception {
log += " testFinished(" + description.getMethodName() + ")";
}
});
junit.run(MethodBlockAfterFireTestStarted.class);
assertEquals(" testStarted(test) init test testFinished(test)", log);
}
}

0 comments on commit 3f736cf

Please sign in to comment.