Skip to content

Commit 00ea1f3

Browse files
authored
Merge pull request #29 from Addepar/calcwu/junit5-idps-2801
[junit5] fix test runtime stats
2 parents ad504cf + 66135de commit 00ea1f3

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/com/facebook/buck/testrunner/JUnitRunner.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ private boolean mightBeJunit4TestClass(Class<?> klass) {
152152
private boolean mightBeJunit5TestClass(Class<?> klass) {
153153
for (Method m : klass.getMethods()) {
154154
if (m.getAnnotation(org.junit.jupiter.api.Test.class) != null ||
155-
m.getAnnotation(org.junit.jupiter.params.ParameterizedTest.class) != null) {
155+
m.getAnnotation(org.junit.jupiter.params.ParameterizedTest.class) != null ||
156+
m.getAnnotation(org.junit.jupiter.api.RepeatedTest.class) != null) {
156157
return true;
157158
}
158159
}

src/com/facebook/buck/testrunner/Junit5TestListener.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,21 @@ public class Junit5TestListener implements TestExecutionListener {
3434
private final Class<?> testClass;
3535

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

3940
public Junit5TestListener(List<TestResult> results, Level stdErrLogLevel, Level stdOutLogLevel, Class<?> testClass) {
4041
this.results = results;
4142
this.stdErrLogLevel = stdErrLogLevel;
4243
this.stdOutLogLevel = stdOutLogLevel;
4344
this.testClass = testClass;
45+
this.testStartTime = System.currentTimeMillis();
46+
this.testPlanStartTime = System.currentTimeMillis();
4447
}
4548

4649
@Override
4750
public void testPlanExecutionStarted(TestPlan testPlan) {
51+
this.testPlanStartTime = System.currentTimeMillis();
4852
listener.testPlanExecutionStarted(testPlan);
4953
}
5054

@@ -54,7 +58,7 @@ public void testPlanExecutionFinished(TestPlan testPlan) {
5458
// testStarted was called for latest test, but not the testFinished
5559
// report all failures as unbounded
5660
for (TestExecutionSummary.Failure failure : listener.getSummary().getFailures()) {
57-
long runtime = System.currentTimeMillis() - startTime;
61+
long runtime = System.currentTimeMillis() - this.testPlanStartTime;
5862
String className = testClass.getCanonicalName();
5963
String methodName = testIdentifier.getDisplayName().replace("()", "");
6064
results.add(
@@ -81,7 +85,6 @@ public void executionStarted(TestIdentifier testIdentifier) {
8185
if (!testIdentifier.isTest()) {
8286
return;
8387
}
84-
8588
// Create an intermediate stdout/stderr to capture any debugging statements (usually in the
8689
// form of System.out.println) the developer is using to debug the test.
8790
originalOut = System.out;
@@ -111,6 +114,7 @@ public void executionStarted(TestIdentifier testIdentifier) {
111114
julLogHandler = addStreamHandler(rootLogger, julLogBytes, formatter, stdOutLogLevel);
112115
julErrLogHandler = addStreamHandler(rootLogger, julErrLogBytes, formatter, stdErrLogLevel);
113116

117+
this.testStartTime = System.currentTimeMillis();
114118
listener.executionStarted(testIdentifier);
115119
}
116120

@@ -179,7 +183,7 @@ public void executionFinished(TestIdentifier testIdentifier, TestExecutionResult
179183

180184
String className = testClass.getCanonicalName();
181185
String methodName = testIdentifier.getDisplayName().replace("()", "");
182-
long runTime = summary.getTimeFinished() - summary.getTimeStarted();
186+
long runTime = System.currentTimeMillis() - this.testStartTime;
183187
results.add(
184188
new TestResult(
185189
className,

0 commit comments

Comments
 (0)