Skip to content

Commit

Permalink
Merge pull request #29 from Addepar/calcwu/junit5-idps-2801
Browse files Browse the repository at this point in the history
[junit5] fix test runtime stats
  • Loading branch information
calcwu authored May 29, 2024
2 parents ad504cf + 66135de commit 00ea1f3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/com/facebook/buck/testrunner/JUnitRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ private boolean mightBeJunit4TestClass(Class<?> klass) {
private boolean mightBeJunit5TestClass(Class<?> klass) {
for (Method m : klass.getMethods()) {
if (m.getAnnotation(org.junit.jupiter.api.Test.class) != null ||
m.getAnnotation(org.junit.jupiter.params.ParameterizedTest.class) != null) {
m.getAnnotation(org.junit.jupiter.params.ParameterizedTest.class) != null ||
m.getAnnotation(org.junit.jupiter.api.RepeatedTest.class) != null) {
return true;
}
}
Expand Down
12 changes: 8 additions & 4 deletions src/com/facebook/buck/testrunner/Junit5TestListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,21 @@ public class Junit5TestListener implements TestExecutionListener {
private final Class<?> testClass;

// To help give a reasonable (though imprecise) guess at the runtime for unpaired failures
private final long startTime = System.currentTimeMillis();
private long testStartTime;
private long testPlanStartTime;

public Junit5TestListener(List<TestResult> results, Level stdErrLogLevel, Level stdOutLogLevel, Class<?> testClass) {
this.results = results;
this.stdErrLogLevel = stdErrLogLevel;
this.stdOutLogLevel = stdOutLogLevel;
this.testClass = testClass;
this.testStartTime = System.currentTimeMillis();
this.testPlanStartTime = System.currentTimeMillis();
}

@Override
public void testPlanExecutionStarted(TestPlan testPlan) {
this.testPlanStartTime = System.currentTimeMillis();
listener.testPlanExecutionStarted(testPlan);
}

Expand All @@ -54,7 +58,7 @@ public void testPlanExecutionFinished(TestPlan testPlan) {
// testStarted was called for latest test, but not the testFinished
// report all failures as unbounded
for (TestExecutionSummary.Failure failure : listener.getSummary().getFailures()) {
long runtime = System.currentTimeMillis() - startTime;
long runtime = System.currentTimeMillis() - this.testPlanStartTime;
String className = testClass.getCanonicalName();
String methodName = testIdentifier.getDisplayName().replace("()", "");
results.add(
Expand All @@ -81,7 +85,6 @@ public void executionStarted(TestIdentifier testIdentifier) {
if (!testIdentifier.isTest()) {
return;
}

// Create an intermediate stdout/stderr to capture any debugging statements (usually in the
// form of System.out.println) the developer is using to debug the test.
originalOut = System.out;
Expand Down Expand Up @@ -111,6 +114,7 @@ public void executionStarted(TestIdentifier testIdentifier) {
julLogHandler = addStreamHandler(rootLogger, julLogBytes, formatter, stdOutLogLevel);
julErrLogHandler = addStreamHandler(rootLogger, julErrLogBytes, formatter, stdErrLogLevel);

this.testStartTime = System.currentTimeMillis();
listener.executionStarted(testIdentifier);
}

Expand Down Expand Up @@ -179,7 +183,7 @@ public void executionFinished(TestIdentifier testIdentifier, TestExecutionResult

String className = testClass.getCanonicalName();
String methodName = testIdentifier.getDisplayName().replace("()", "");
long runTime = summary.getTimeFinished() - summary.getTimeStarted();
long runTime = System.currentTimeMillis() - this.testStartTime;
results.add(
new TestResult(
className,
Expand Down

0 comments on commit 00ea1f3

Please sign in to comment.