Skip to content

Commit

Permalink
Merge pull request #31 from Addepar/ztai/failure-count
Browse files Browse the repository at this point in the history
JUnit5: fix failure count
  • Loading branch information
ztai-add authored Jul 6, 2024
2 parents 9a2dc3f + acf6b3d commit 21bb1ca
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 32 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 @@ -96,7 +96,8 @@ public void run() throws Throwable {
requestBuilder = requestBuilder.selectors(selectClass(testClass));
} else {
for (TestSelector selector : testSelectorList.getSelectors()) {
if (selector.matchesClassName(testClass.getSimpleName())) {
if (selector.matchesClassName(testClass.getSimpleName()) ||
selector.matchesClassName(testClass.getCanonicalName())) {
if (selector.isMatchAnyMethod()) {
requestBuilder = requestBuilder.selectors(selectClass(testClass));
} else {
Expand Down
39 changes: 8 additions & 31 deletions src/com/facebook/buck/testrunner/Junit5TestListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,6 @@ public void testPlanExecutionStarted(TestPlan testPlan) {
listener.testPlanExecutionStarted(testPlan);
}

// compare to Junit4TestListener.testRunFinished
@Override
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() - this.testPlanStartTime;
String className = testClass.getCanonicalName();
String methodName = testIdentifier.getDisplayName().replace("()", "");
results.add(
new TestResult(
className,
methodName,
runtime,
ResultType.FAILURE,
failure.getException(),
null,
null));
}
}

// compare to Junit4TestListener.testIgnored
@Override
public void executionSkipped(TestIdentifier testIdentifier, String reason) {
Expand Down Expand Up @@ -150,16 +129,14 @@ public void executionFinished(TestIdentifier testIdentifier, TestExecutionResult
stdErrStream.flush();

TestExecutionSummary summary = listener.getSummary();
long numFailures = summary.getTestsFailedCount();

TestExecutionSummary.Failure failure;
ResultType type;
if (numFailures == 0) {
failure = null;
type = ResultType.SUCCESS;
} else {
failure = summary.getFailures().get(0);
type = ResultType.FAILURE;
TestExecutionSummary.Failure failure = null;
ResultType type = ResultType.SUCCESS;
for(TestExecutionSummary.Failure f : summary.getFailures()) {
if(f.getTestIdentifier().equals(testIdentifier)) {
failure = f;
type = ResultType.FAILURE;
break;
}
}

StringBuilder stdOut = new StringBuilder();
Expand Down

0 comments on commit 21bb1ca

Please sign in to comment.