-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Synthesize start/finished events for reported failures
When Spock data-provider preparation fails early, it only calls `RunListener.testFailure` but not `testFinished` which caused the Vintage engine to never report the failure. Now, when `testFailure` is called a `testStarted` event is synthesized unless it was already reported. The existing handling of synthetic start events then reports it as finished. Fixes #1845.
- Loading branch information
1 parent
e3d13cf
commit f9c509d
Showing
5 changed files
with
118 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
...unit4/JUnit4SuiteWithJUnit4TestCaseWithFailingDescriptionThatIsNotReportedAsFinished.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Copyright 2015-2019 the original author or authors. | ||
* | ||
* All rights reserved. This program and the accompanying materials are | ||
* made available under the terms of the Eclipse Public License v2.0 which | ||
* accompanies this distribution and is available at | ||
* | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
*/ | ||
|
||
package org.junit.vintage.engine.samples.junit4; | ||
|
||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Suite; | ||
import org.junit.runners.Suite.SuiteClasses; | ||
|
||
@RunWith(Suite.class) | ||
@SuiteClasses({ JUnit4TestCaseWithFailingDescriptionThatIsNotReportedAsFinished.class, | ||
PlainJUnit4TestCaseWithSingleTestWhichFails.class }) | ||
public class JUnit4SuiteWithJUnit4TestCaseWithFailingDescriptionThatIsNotReportedAsFinished { | ||
} |
24 changes: 24 additions & 0 deletions
24
...ngine/samples/junit4/JUnit4TestCaseWithFailingDescriptionThatIsNotReportedAsFinished.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright 2015-2019 the original author or authors. | ||
* | ||
* All rights reserved. This program and the accompanying materials are | ||
* made available under the terms of the Eclipse Public License v2.0 which | ||
* accompanies this distribution and is available at | ||
* | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
*/ | ||
|
||
package org.junit.vintage.engine.samples.junit4; | ||
|
||
import static org.junit.Assert.fail; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
@RunWith(RunnerThatOnlyReportsFailures.class) | ||
public class JUnit4TestCaseWithFailingDescriptionThatIsNotReportedAsFinished { | ||
@Test | ||
public void testWithMissingEvents() { | ||
fail("boom"); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
.../src/test/java/org/junit/vintage/engine/samples/junit4/RunnerThatOnlyReportsFailures.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright 2015-2019 the original author or authors. | ||
* | ||
* All rights reserved. This program and the accompanying materials are | ||
* made available under the terms of the Eclipse Public License v2.0 which | ||
* accompanies this distribution and is available at | ||
* | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
*/ | ||
|
||
package org.junit.vintage.engine.samples.junit4; | ||
|
||
import org.junit.runner.notification.Failure; | ||
import org.junit.runner.notification.RunNotifier; | ||
import org.junit.runners.BlockJUnit4ClassRunner; | ||
import org.junit.runners.model.FrameworkMethod; | ||
import org.junit.runners.model.InitializationError; | ||
import org.junit.runners.model.Statement; | ||
|
||
public class RunnerThatOnlyReportsFailures extends BlockJUnit4ClassRunner { | ||
public RunnerThatOnlyReportsFailures(Class<?> klass) throws InitializationError { | ||
super(klass); | ||
} | ||
|
||
@Override | ||
protected void runChild(FrameworkMethod method, RunNotifier notifier) { | ||
Statement statement = methodBlock(method); | ||
try { | ||
statement.evaluate(); | ||
} | ||
catch (Throwable e) { | ||
notifier.fireTestFailure(new Failure(describeChild(method), e)); | ||
} | ||
} | ||
} |