Uploaded image for project: 'Maven Surefire'
  1. Maven Surefire
  2. SUREFIRE-1577

JUnit 5 surefire-provider ignores configuration properties in POM

    XMLWordPrintableJSON

Details

    Description

      I wanted to exclude some tags using

      					<properties>
      						<excludeTags>external</excludeTags>
      					</properties>
      

      but the test tagged thus was still run by surefire.

      Reproducer

      I took the junit5 sample project https://github.com/junit-team/junit5-samples/tree/r5.3.1/junit5-jupiter-starter-maven and added a tag to one test. I now want to skip running this test. (Ignore the commented out xml now.)

      diff --git a/junit5-jupiter-starter-maven/pom.xml b/junit5-jupiter-starter-maven/pom.xml
      index 6c217cf..27ec850 100644
      --- a/junit5-jupiter-starter-maven/pom.xml
      +++ b/junit5-jupiter-starter-maven/pom.xml
      @@ -13,6 +13,8 @@
       		<maven.compiler.target>${maven.compiler.source}</maven.compiler.target>
       
       		<junit.jupiter.version>5.3.1</junit.jupiter.version>
      +
      +		<!--<junit.platform.version>1.3.1</junit.platform.version>-->
       	</properties>
       
       	<dependencies>
      @@ -42,6 +44,18 @@
       			<plugin>
       				<artifactId>maven-surefire-plugin</artifactId>
       				<version>2.22.0</version>
      +				<configuration>
      +					<properties>
      +						<excludeTags>external</excludeTags>
      +					</properties>
      +				</configuration>
      +				<!--<dependencies>-->
      +					<!--<dependency>-->
      +						<!--<groupId>org.junit.platform</groupId>-->
      +						<!--<artifactId>junit-platform-surefire-provider</artifactId>-->
      +						<!--<version>${junit.platform.version}</version>-->
      +					<!--</dependency>-->
      +				<!--</dependencies>-->
       			</plugin>
       		</plugins>
       	</build>
      diff --git a/junit5-jupiter-starter-maven/src/test/java/com/example/project/CalculatorTests.java b/junit5-jupiter-starter-maven/src/test/java/com/example/project/CalculatorTests.java
      index 0d4f546..8994070 100644
      --- a/junit5-jupiter-starter-maven/src/test/java/com/example/project/CalculatorTests.java
      +++ b/junit5-jupiter-starter-maven/src/test/java/com/example/project/CalculatorTests.java
      @@ -11,8 +11,10 @@
       package com.example.project;
       
       import static org.junit.jupiter.api.Assertions.assertEquals;
      +import static org.junit.jupiter.api.Assertions.fail;
       
       import org.junit.jupiter.api.DisplayName;
      +import org.junit.jupiter.api.Tag;
       import org.junit.jupiter.api.Test;
       import org.junit.jupiter.params.ParameterizedTest;
       import org.junit.jupiter.params.provider.CsvSource;
      @@ -20,8 +22,10 @@ import org.junit.jupiter.params.provider.CsvSource;
       class CalculatorTests {
       
       	@Test
      +	@Tag("external")
       	@DisplayName("1 + 1 = 2")
       	void addsTwoNumbers() {
      +		fail("failing an 'external' test");
       		Calculator calculator = new Calculator();
       		assertEquals(2, calculator.add(1, 1), "1 + 1 should equal 2");
       	}
      

      If I now run mvn package, I see fail from the test which was supposed to be skipped.

      If I uncomment the commented out lines in the XML, I get the below warning, but the test I meant to skip is correctly skipped, and the test run passes.

       +-------------------------------------------------------------------------------+
       | WARNING:                                                                      |
       | The junit-platform-surefire-provider has been deprecated and is scheduled to  |
      

      Attachments

        Activity

          People

            tibordigana Tibor Digana
            jdanek Jiri Daněk
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: