|
| 1 | +package org.apache.maven.surefire.its.jiras; |
| 2 | + |
| 3 | +/* |
| 4 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 5 | + * or more contributor license agreements. See the NOTICE file |
| 6 | + * distributed with this work for additional information |
| 7 | + * regarding copyright ownership. The ASF licenses this file |
| 8 | + * to you under the Apache License, Version 2.0 (the |
| 9 | + * "License"); you may not use this file except in compliance |
| 10 | + * with the License. You may obtain a copy of the License at |
| 11 | + * |
| 12 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 13 | + * |
| 14 | + * Unless required by applicable law or agreed to in writing, |
| 15 | + * software distributed under the License is distributed on an |
| 16 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 17 | + * KIND, either express or implied. See the License for the |
| 18 | + * specific language governing permissions and limitations |
| 19 | + * under the License. |
| 20 | + */ |
| 21 | + |
| 22 | +import static java.nio.charset.StandardCharsets.UTF_8; |
| 23 | + |
| 24 | +import org.apache.maven.it.VerificationException; |
| 25 | +import org.apache.maven.surefire.its.fixture.OutputValidator; |
| 26 | +import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase; |
| 27 | +import org.hamcrest.Matchers; |
| 28 | +import org.junit.Test; |
| 29 | + |
| 30 | +/** |
| 31 | + * Integration Tests for SUREFIRE-2065 |
| 32 | + */ |
| 33 | +@SuppressWarnings( "checkstyle:magicnumber" ) |
| 34 | +public class Surefire2065IT extends SurefireJUnit4IntegrationTestCase |
| 35 | +{ |
| 36 | + @Test |
| 37 | + public void shouldNotDetectFlakyTestsWhenCombiningJunit4And5Tests() throws VerificationException |
| 38 | + { |
| 39 | + OutputValidator validator = unpack( "surefire-2065-common" ) |
| 40 | + .mavenTestFailureIgnore( true ) |
| 41 | + .executeTest() |
| 42 | + .assertTestSuiteResults( 8, 0, 4, 0, 0 ); |
| 43 | + |
| 44 | + assertJunit4( validator ); |
| 45 | + assertJunit5( validator ); |
| 46 | + } |
| 47 | + |
| 48 | + @Test |
| 49 | + public void shouldNotDetectFlakyTestsWhenRunningOnlyJunit4() throws VerificationException |
| 50 | + { |
| 51 | + OutputValidator validator = unpack( "surefire-2065-junit4" ) |
| 52 | + .mavenTestFailureIgnore( true ) |
| 53 | + .executeTest() |
| 54 | + .assertTestSuiteResults( 4, 0, 2, 0, 0 ); |
| 55 | + |
| 56 | + assertJunit4( validator ); |
| 57 | + } |
| 58 | + |
| 59 | + @Test |
| 60 | + public void shouldNotDetectFlakyTestsWhenRunningOnlyJunit5() throws VerificationException |
| 61 | + { |
| 62 | + OutputValidator validator = unpack( "surefire-2065-junit5" ) |
| 63 | + .mavenTestFailureIgnore( true ) |
| 64 | + .executeTest() |
| 65 | + .assertTestSuiteResults( 4, 0, 2, 0, 0 ); |
| 66 | + |
| 67 | + assertJunit5( validator ); |
| 68 | + } |
| 69 | + |
| 70 | + private static void assertJunit4( OutputValidator validator ) |
| 71 | + { |
| 72 | + validator.getSurefireReportsFile( "TEST-pkg.junit4.ParameterizedTest.xml", UTF_8 ) |
| 73 | + .assertContainsText( Matchers.matchesPattern( "^ *<testcase name=\"notFlaky\\[0]\".*/>$" ) ) |
| 74 | + .assertContainsText( Matchers.matchesPattern( "^ *<testcase name=\"notFlaky\\[1]\".*[^/]>$" ) ) |
| 75 | + .assertContainsText( "<failure message=" ) |
| 76 | + .assertContainsText( "<rerunFailure message=" ) |
| 77 | + .assertNotContainsText( "<flakyFailure message=" ); |
| 78 | + |
| 79 | + validator.getSurefireReportsFile( "TEST-pkg.junit4.ParameterizedWithDisplayNameTest.xml", UTF_8 ) |
| 80 | + .assertContainsText( Matchers.matchesPattern( "^ *<testcase name=\"notFlaky\\[value=0]\".*/>$" ) ) |
| 81 | + .assertContainsText( Matchers.matchesPattern( "^ *<testcase name=\"notFlaky\\[value=1]\".*[^/]>$" ) ) |
| 82 | + .assertContainsText( "<failure message=" ) |
| 83 | + .assertContainsText( "<rerunFailure message=" ) |
| 84 | + .assertNotContainsText( "<flakyFailure message=" ); |
| 85 | + } |
| 86 | + |
| 87 | + private static void assertJunit5( OutputValidator validator ) |
| 88 | + { |
| 89 | + validator.getSurefireReportsFile( "TEST-pkg.junit5.ParameterizedTest.xml", UTF_8 ) |
| 90 | + .assertContainsText( Matchers.matchesPattern( "^ *<testcase name=\"notFlaky\\(int\\)\\[1]\".*/>$" ) ) |
| 91 | + .assertContainsText( Matchers.matchesPattern( "^ *<testcase name=\"notFlaky\\(int\\)\\[2]\".*[^/]>$" ) ) |
| 92 | + .assertContainsText( "<failure message=" ) |
| 93 | + .assertContainsText( "<rerunFailure message=" ) |
| 94 | + .assertNotContainsText( "<flakyFailure message=" ); |
| 95 | + |
| 96 | + validator.getSurefireReportsFile( "TEST-pkg.junit5.ParameterizedWithDisplayNameTest.xml", UTF_8 ) |
| 97 | + .assertContainsText( Matchers.matchesPattern( "^ *<testcase name=\"notFlaky\\(int\\)\\[1]\".*/>$" ) ) |
| 98 | + .assertContainsText( Matchers.matchesPattern( "^ *<testcase name=\"notFlaky\\(int\\)\\[2]\".*[^/]>$" ) ) |
| 99 | + .assertContainsText( "<failure message=" ) |
| 100 | + .assertContainsText( "<rerunFailure message=" ) |
| 101 | + .assertNotContainsText( "<flakyFailure message=" ); |
| 102 | + } |
| 103 | +} |
0 commit comments