GeezerVison is showing github.com — Implement fail-fast behavior for JUnit Platform provider (#3155) · apache/maven-surefire@0fbfb27
File treeExpand file treeCollapse file tree Open diff view settings maven-surefire-plugin/src/site/apt/examples surefire-api/src/main/java/org/apache/maven/surefire/api/report java/org/apache/maven/surefire/its resources/fail-fast-junit-platform
surefire-junit-platform/src main/java/org/apache/maven/surefire/junitplatform test/java/org/apache/maven/surefire/junitplatform
surefire-testng-utils/src/main/java/org/apache/maven/surefire/testng/utils surefire-testng/src/main/java/org/apache/maven/surefire/testng
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: maven-surefire-plugin/src/site/apt/examples/skip-after-failure.apt.vm +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -41,8 +41,8 @@ Skipping Tests After the Nth Failure or Error | 41 | 41 |
| 42 | 42 | Prerequisite | 43 | 43 |
| 44 | | - Use ${project.artifactId} 2.19 or higher, JUnit 4.0 or higher, or | 45 | | - TestNG 5.10 or higher. | | 44 | + Use ${project.artifactId} 2.19 or higher, JUnit 4.0 or higher, TestNG 5.10 or | | 45 | + higher, or JUnit Platform 6.0 or higher. | 46 | 46 |
| 47 | 47 | If version of TestNG is lower than 5.10 while the parameter | 48 | 48 | <<<skipAfterFailureCount>>> is set, the plugin fails with error: | |
Collapse file Copy file name to clipboardExpand all lines: surefire-api/src/main/java/org/apache/maven/surefire/api/report/Stoppable.java +10-3Lines changed: 10 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 16 | 16 | * specific language governing permissions and limitations | 17 | 17 | * under the License. | 18 | 18 | */ | 19 | | -package org.apache.maven.surefire.testng.utils; | 20 | | - | 21 | | -import org.apache.maven.surefire.api.report.RunListener; | | 19 | +package org.apache.maven.surefire.api.report; | 22 | 20 |
| 23 | 21 | /** | 24 | 22 | * Covers configuration parameter {@code skipAfterFailureCount}. | 25 | 23 | * | 26 | 24 | | 27 | 25 | * @since 2.19 | 28 | 26 | */ | | 27 | +@FunctionalInterface | 29 | 28 | public interface Stoppable { | | 29 | + | | 30 | + /** | | 31 | + * Null object for use when fail-fast behavior is disabled. | | 32 | + */ | | 33 | + Stoppable NOOP = () -> { | | 34 | + // do nothing | | 35 | + }; | | 36 | + | 30 | 37 | /** | 31 | 38 | * Delegates this call to {@link RunListener#testExecutionSkippedByUser()}. | 32 | 39 | */ | |
Collapse file Copy file name to clipboardExpand all lines: surefire-its/src/test/java/org/apache/maven/surefire/its/AbstractFailFastIT.java +7-1Lines changed: 7 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -110,8 +110,14 @@ static Map<String, String> props(int forkCount, int skipAfterFailureCount, boole | 110 | 110 | @Test | 111 | 111 | public void test() throws Exception { | 112 | 112 | String cls = useProcessPipes ? LEGACY_FORK_NODE : SUREFIRE_FORK_NODE; | 113 | | - prepare(description, profile, properties) | | 113 | + OutputValidator validator = prepare(description, profile, properties); | | 114 | + validator | 114 | 115 | .assertTestSuiteResults(total, errors, failures, skipped) | 115 | 116 | .assertThatLogLine(containsString("Found implementation of fork node factory: " + cls), equalTo(1)); | | 117 | + performExtraChecks(validator); | | 118 | + } | | 119 | + | | 120 | + protected void performExtraChecks(OutputValidator validator) throws Exception { | | 121 | + // may be overriden in subclasses | 116 | 122 | } | 117 | 123 | } |
Collapse file Copy file name to clipboard +85Lines changed: 85 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +/* | | 2 | + * Licensed to the Apache Software Foundation (ASF) under one | | 3 | + * or more contributor license agreements. See the NOTICE file | | 4 | + * distributed with this work for additional information | | 5 | + * regarding copyright ownership. The ASF licenses this file | | 6 | + * to you under the Apache License, Version 2.0 (the | | 7 | + * "License"); you may not use this file except in compliance | | 8 | + * with the License. You may obtain a copy of the License at | | 9 | + * | | 10 | + * http://www.apache.org/licenses/LICENSE-2.0 | | 11 | + * | | 12 | + * Unless required by applicable law or agreed to in writing, | | 13 | + * software distributed under the License is distributed on an | | 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | | 15 | + * KIND, either express or implied. See the License for the | | 16 | + * specific language governing permissions and limitations | | 17 | + * under the License. | | 18 | + */ | | 19 | +package org.apache.maven.surefire.its; | | 20 | + | | 21 | +import java.util.Arrays; | | 22 | +import java.util.Map; | | 23 | + | | 24 | +import org.apache.maven.surefire.its.fixture.OutputValidator; | | 25 | +import org.junit.Test; | | 26 | +import org.junit.runners.Parameterized.Parameters; | | 27 | + | | 28 | +import static java.lang.Integer.parseInt; | | 29 | +import static org.apache.maven.surefire.its.fixture.HelperAssertions.assumeJavaVersion; | | 30 | +import static org.hamcrest.Matchers.containsString; | | 31 | +import static org.hamcrest.Matchers.equalTo; | | 32 | + | | 33 | +public class FailFastJUnitPlatformIT extends AbstractFailFastIT { | | 34 | + | | 35 | + @Parameters(name = "{0}") | | 36 | + public static Iterable<Object[]> data() { | | 37 | + // description profile forkCount, | | 38 | + // | | | fail-fast-count, | | 39 | + // | | | | reuseForks | | 40 | + // | | | | | total | | 41 | + // | | | | | | failures | | 42 | + // | | | | | | | errors | | 43 | + // | | | | | | | | skipped | | 44 | + // | | | | | | | | | pipes | | 45 | + return Arrays.asList( // | | | | | | | | | | | 46 | + new Object[] {"oneFork-ff1", null, props(1, 1, true), 5, 0, 1, 4, true}, | | 47 | + new Object[] {"oneFork-ff2", null, props(1, 2, true), 5, 0, 2, 3, true}, | | 48 | + new Object[] {"twoForks-ff1", null, props(2, 1, true), 5, 0, 2, 3, true}, | | 49 | + new Object[] {"twoForks-ff2", null, props(2, 2, true), 5, 0, 2, 2, true}, | | 50 | + new Object[] {"oneFork-ff3", null, props(1, 3, true), 5, 0, 2, 0, true}, | | 51 | + new Object[] {"twoForks-ff3", null, props(2, 3, true), 5, 0, 2, 0, true}, | | 52 | + new Object[] { | | 53 | + "unsupported-version", null, withUnsupportedJUnitVersion(props(2, 1, true)), 5, 0, 2, 0, true | | 54 | + }); | | 55 | + } | | 56 | + | | 57 | + private static Map<String, String> withUnsupportedJUnitVersion(Map<String, String> props) { | | 58 | + props.put("junit.version", "5.13.3"); | | 59 | + return props; | | 60 | + } | | 61 | + | | 62 | + @Override | | 63 | + protected String withProvider() { | | 64 | + return "junit-platform"; | | 65 | + } | | 66 | + | | 67 | + @Override | | 68 | + @Test | | 69 | + public void test() throws Exception { | | 70 | + if (!"unsupported-version".equals(description)) { | | 71 | + // JUnit 6.0.0 requires Java 17+ | | 72 | + assumeJavaVersion(17); | | 73 | + } | | 74 | + super.test(); | | 75 | + } | | 76 | + | | 77 | + @Override | | 78 | + protected void performExtraChecks(OutputValidator validator) throws Exception { | | 79 | + if ("unsupported-version".equals(description)) { | | 80 | + int forkCount = parseInt(properties.get("forkCount")); | | 81 | + validator.assertThatLogLine( | | 82 | + containsString("An attempt was made to cancel the current test run"), equalTo(forkCount)); | | 83 | + } | | 84 | + } | | 85 | +} |
Collapse file Copy file name to clipboard +62Lines changed: 62 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +<?xml version="1.0" encoding="UTF-8"?> | | 2 | +<!-- | | 3 | + ~ Licensed to the Apache Software Foundation (ASF) under one | | 4 | + ~ or more contributor license agreements. See the NOTICE file | | 5 | + ~ distributed with this work for additional information | | 6 | + ~ regarding copyright ownership. The ASF licenses this file | | 7 | + ~ to you under the Apache License, Version 2.0 (the | | 8 | + ~ "License"); you may not use this file except in compliance | | 9 | + ~ with the License. You may obtain a copy of the License at | | 10 | + ~ | | 11 | + ~ http://www.apache.org/licenses/LICENSE-2.0 | | 12 | + ~ | | 13 | + ~ Unless required by applicable law or agreed to in writing, | | 14 | + ~ software distributed under the License is distributed on an | | 15 | + ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | | 16 | + ~ KIND, either express or implied. See the License for the | | 17 | + ~ specific language governing permissions and limitations | | 18 | + ~ under the License. | | 19 | + --> | | 20 | + | | 21 | +<project xmlns="http://maven.apache.org/POM/4.0.0" | | 22 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | | 23 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | | 24 | + <modelVersion>4.0.0</modelVersion> | | 25 | + | | 26 | + <groupId>org.apache.maven.plugins.surefire</groupId> | | 27 | + <artifactId>fail-fast-junit-platform</artifactId> | | 28 | + <version>1.0</version> | | 29 | + | | 30 | + <properties> | | 31 | + <maven.compiler.release>${java.specification.version}</maven.compiler.release> | | 32 | + <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> | | 33 | + <junit.version>6.0.0-M2</junit.version> | | 34 | + </properties> | | 35 | + | | 36 | + <dependencies> | | 37 | + <dependency> | | 38 | + <groupId>org.junit.jupiter</groupId> | | 39 | + <artifactId>junit-jupiter-api</artifactId> | | 40 | + <version>${junit.version}</version> | | 41 | + <scope>test</scope> | | 42 | + </dependency> | | 43 | + </dependencies> | | 44 | + <build> | | 45 | + <plugins> | | 46 | + <plugin> | | 47 | + <groupId>org.apache.maven.plugins</groupId> | | 48 | + <artifactId>maven-surefire-plugin</artifactId> | | 49 | + <version>${surefire.version}</version> | | 50 | + <configuration> | | 51 | + <runOrder>alphabetical</runOrder> | | 52 | + </configuration> | | 53 | + </plugin> | | 54 | + <plugin> | | 55 | + <groupId>org.apache.maven.plugins</groupId> | | 56 | + <artifactId>maven-compiler-plugin</artifactId> | | 57 | + <version>3.14.0</version> | | 58 | + </plugin> | | 59 | + </plugins> | | 60 | + </build> | | 61 | + | | 62 | +</project> |
Collapse file Copy file name to clipboard +13Lines changed: 13 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +package pkg; | | 2 | + | | 3 | +import org.junit.jupiter.api.Test; | | 4 | + | | 5 | +import static java.util.concurrent.TimeUnit.MILLISECONDS; | | 6 | + | | 7 | +class ATest { | | 8 | + @Test | | 9 | + void test() throws Exception { | | 10 | + MILLISECONDS.sleep(1_000); | | 11 | + throw new RuntimeException(); | | 12 | + } | | 13 | +} |
Collapse file Copy file name to clipboard +13Lines changed: 13 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +package pkg; | | 2 | + | | 3 | +import org.junit.jupiter.api.Test; | | 4 | + | | 5 | +import static java.util.concurrent.TimeUnit.MILLISECONDS; | | 6 | + | | 7 | +class BTest { | | 8 | + @Test | | 9 | + void test() throws Exception { | | 10 | + MILLISECONDS.sleep(2_000); | | 11 | + throw new RuntimeException(); | | 12 | + } | | 13 | +} |
Collapse file Copy file name to clipboard +12Lines changed: 12 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +package pkg; | | 2 | + | | 3 | +import org.junit.jupiter.api.Test; | | 4 | + | | 5 | +import static java.util.concurrent.TimeUnit.MILLISECONDS; | | 6 | + | | 7 | +class CTest { | | 8 | + @Test | | 9 | + void test() throws Exception { | | 10 | + MILLISECONDS.sleep(2_000); | | 11 | + } | | 12 | +} |
Collapse file Copy file name to clipboard +11Lines changed: 11 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +package pkg; | | 2 | + | | 3 | +import org.junit.jupiter.api.Test; | | 4 | + | | 5 | +import static java.util.concurrent.TimeUnit.MILLISECONDS; | | 6 | + | | 7 | +class DTest { | | 8 | + @Test | | 9 | + void test() { | | 10 | + } | | 11 | +} |
Collapse file Copy file name to clipboard +11Lines changed: 11 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +package pkg; | | 2 | + | | 3 | +import static java.util.concurrent.TimeUnit.MILLISECONDS; | | 4 | + | | 5 | +import org.junit.jupiter.api.Test; | | 6 | + | | 7 | +class ETest { | | 8 | + @Test | | 9 | + void test() { | | 10 | + } | | 11 | +} |
|