Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.maven.surefire.its;

import org.apache.maven.shared.verifier.VerificationException;
import org.apache.maven.surefire.its.fixture.OutputValidator;
import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase;
import org.junit.jupiter.api.Test;

import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;

/**
* Integration test for JUnit 4 @AfterClass that always fails.
* Verifies that surefire properly reports errors when class-level teardown throws.
*/
public class JUnit4FailingAfterClassIT extends SurefireJUnit4IntegrationTestCase {
private static final String VERSION = "4.13.2";

@Test
public void testAfterClassFailureIsReported() {
OutputValidator outputValidator = unpack("junit4-failing-after-class", "-norerun")
.setJUnitVersion(VERSION)
.maven()
.withFailure()
.executeTest();

outputValidator.verifyTextInLog("AfterClass always fails");

outputValidator
.getSurefireReportsXmlFile("TEST-junit4.PassingTest.xml")
.assertContainsText("tests=\"1\" errors=\"0\"");

outputValidator
.getSurefireReportsXmlFile("TEST-junit4.AlwaysFailingAfterClassTest.xml")
.assertContainsText("name=\"initializationError\"")
.assertContainsText("errors=\"0\"")
.assertContainsText("flakes=\"1\"");
}

@Test
public void testAfterClassFailureWithRerun() throws VerificationException {
OutputValidator outputValidator = unpack("junit4-failing-after-class", "-rerun")
.setJUnitVersion(VERSION)
.maven()
.addGoal("-Dsurefire.rerunFailingTestsCount=2")
.executeTest();

outputValidator
.getSurefireReportsXmlFile("TEST-junit4.AlwaysFailingAfterClassTest.xml")
.assertContainsText("name=\"initializationError\"")
.assertContainsText("errors=\"0\"")
.assertContainsText("flakes=\"1\"");

outputValidator.assertThatLogLine(containsString("testOne passed"), is(3));
outputValidator.assertThatLogLine(containsString("testTwo passed"), is(3));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.maven.surefire.its;

import org.apache.maven.shared.verifier.VerificationException;
import org.apache.maven.surefire.its.fixture.OutputValidator;
import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase;
import org.junit.jupiter.api.Test;

import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;

/**
* Integration test for JUnit 5 @AfterAll that always fails.
* Verifies that surefire properly reports errors when class-level teardown throws.
*/
public class JUnit5FailingAfterAllIT extends SurefireJUnit4IntegrationTestCase {
private static final String VERSION = "5.9.1";

@Test
public void testAfterAllFailureIsReported() {
OutputValidator outputValidator = unpack("junit5-failing-after-all", "-norerun")
.setJUnitVersion(VERSION)
.maven()
.withFailure()
.executeTest();

outputValidator.verifyTextInLog("AfterAll always fails");

outputValidator
.getSurefireReportsXmlFile("TEST-junit5.PassingTest.xml")
.assertContainsText("tests=\"1\" errors=\"0\"");

outputValidator
.getSurefireReportsXmlFile("TEST-junit5.AlwaysFailingAfterAllTest.xml")
.assertContainsText("name=\"initializationError\"")
.assertContainsText("errors=\"0\"")
.assertContainsText("flakes=\"1\"");
}

@Test
public void testAfterAllFailureWithRerun() throws VerificationException {
OutputValidator outputValidator = unpack("junit5-failing-after-all", "-rerun")
.setJUnitVersion(VERSION)
.maven()
.addGoal("-Dsurefire.rerunFailingTestsCount=2")
.executeTest();

outputValidator
.getSurefireReportsXmlFile("TEST-junit5.AlwaysFailingAfterAllTest.xml")
.assertContainsText("name=\"initializationError\"")
.assertContainsText("errors=\"0\"")
.assertContainsText("flakes=\"1\"");

outputValidator.assertThatLogLine(containsString("testOne passed"), is(3));
outputValidator.assertThatLogLine(containsString("testTwo passed"), is(3));
}
}
55 changes: 55 additions & 0 deletions surefire-its/src/test/resources/junit4-failing-after-class/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one
~ or more contributor license agreements. See the NOTICE file
~ distributed with this work for additional information
~ regarding copyright ownership. The ASF licenses this file
~ to you under the Apache License, Version 2.0 (the
~ "License"); you may not use this file except in compliance
~ with the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.apache.maven.plugins.surefire</groupId>
<artifactId>junit4-failing-after-class</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Test for failing @AfterClass in JUnit 4</name>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.version}</version>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package junit4;

import org.junit.AfterClass;
import org.junit.Test;

/**
* Test class with @AfterClass that always fails.
* All test methods pass, but the class-level teardown always throws.
*/
public class AlwaysFailingAfterClassTest
{
@AfterClass
public static void tearDown()
{
throw new IllegalStateException( "AfterClass always fails" );
}

@Test
public void testOne()
{
System.out.println( "testOne passed" );
}

@Test
public void testTwo()
{
System.out.println( "testTwo passed" );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package junit4;

import org.junit.Test;

/**
* A simple passing test class to verify that other tests are unaffected
* by the failing @AfterClass in another test class.
*/
public class PassingTest
{
@Test
public void testPassingOne()
{
System.out.println( "testPassingOne passed" );
}
}
57 changes: 57 additions & 0 deletions surefire-its/src/test/resources/junit5-failing-after-all/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one
~ or more contributor license agreements. See the NOTICE file
~ distributed with this work for additional information
~ regarding copyright ownership. The ASF licenses this file
~ to you under the Apache License, Version 2.0 (the
~ "License"); you may not use this file except in compliance
~ with the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.apache.maven.plugins.surefire</groupId>
<artifactId>junit5-failing-after-all</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Test for failing @AfterAll in JUnit 5</name>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.version}</version>
</plugin>
</plugins>
</pluginManagement>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package junit5;

import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;

/**
* Test class with @AfterAll that always fails.
* All test methods pass, but the class-level teardown always throws.
*/
public class AlwaysFailingAfterAllTest
{
@AfterAll
static void tearDown()
{
throw new IllegalStateException( "AfterAll always fails" );
}

@Test
public void testOne()
{
System.out.println( "testOne passed" );
}

@Test
public void testTwo()
{
System.out.println( "testTwo passed" );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package junit5;

import org.junit.jupiter.api.Test;

/**
* A simple passing test class to verify that other tests are unaffected
* by the failing @AfterAll in another test class.
*/
public class PassingTest
{
@Test
public void testPassingOne()
{
System.out.println( "testPassingOne passed" );
}
}