View Javadoc
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.jiras;
20  
21  import java.util.Arrays;
22  
23  import org.apache.maven.surefire.its.fixture.OutputValidator;
24  import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase;
25  import org.junit.Test;
26  import org.junit.runner.RunWith;
27  import org.junit.runners.Parameterized;
28  import org.junit.runners.Parameterized.Parameter;
29  import org.junit.runners.Parameterized.Parameters;
30  
31  import static java.nio.charset.StandardCharsets.UTF_8;
32  
33  /**
34   * Integration Test for SUREFIRE-2117
35   */
36  @RunWith(Parameterized.class)
37  @SuppressWarnings("checkstyle:magicnumber")
38  public class Surefire2117XmlReportingNestedIT extends SurefireJUnit4IntegrationTestCase {
39      @Parameter
40      @SuppressWarnings("checkstyle:visibilitymodifier")
41      public String jupiterVersion;
42  
43      @Parameters(name = "{0}")
44      public static Iterable<?> junitJupiterVersions() {
45          return Arrays.asList("5.2.0", "5.8.2", "5.9.1");
46      }
47  
48      @Test
49      public void testXmlReport() {
50          OutputValidator validator = unpack("surefire-2117-xml-reporting-nested", "-" + jupiterVersion)
51                  .sysProp("junit5.version", jupiterVersion)
52                  .executeTest()
53                  .verifyErrorFree(9);
54  
55          validator
56                  .getSurefireReportsFile("TEST-jira2117.NestedJupiterTest$A.xml", UTF_8)
57                  .assertContainsText("<testcase name=\"level1_test\" " + "classname=\"jira2117.NestedJupiterTest$A\"");
58  
59          validator
60                  .getSurefireReportsFile("TEST-jira2117.NestedJupiterTest$B$C.xml", UTF_8)
61                  .assertContainsText("<testcase name=\"level2_test_nonparameterized\" "
62                          + "classname=\"jira2117.NestedJupiterTest$B$C\"")
63                  .assertContainsText("<testcase name=\"level2_test_parameterized(String)[1] paramValue1\" "
64                          + "classname=\"jira2117.NestedJupiterTest$B$C\"")
65                  .assertContainsText("<testcase name=\"level2_test_parameterized(String)[2] paramValue2\" "
66                          + "classname=\"jira2117.NestedJupiterTest$B$C\"");
67  
68          String expectedDisplayNameForNestedClassA =
69                  String.join(" ", "Display name of the main test class", "Display name of level 1 nested class A");
70  
71          validator
72                  .getSurefireReportsFile("TEST-jira2117.NestedDisplayNameTest$A.xml", UTF_8)
73                  .assertContainsText("<testcase name=\"level1_test_without_display_name\" " + "classname=\""
74                          + expectedDisplayNameForNestedClassA + "\"")
75                  .assertContainsText("<testcase name=\"Display name of level 1 test method\" " + "classname=\""
76                          + expectedDisplayNameForNestedClassA + "\"");
77  
78          String expectedDisplayNameForNestedClassC = String.join(
79                  " ",
80                  "Display name of the main test class",
81                  "Display name of level 1 nested class B",
82                  "Display name of level 2 nested class C");
83  
84          validator
85                  .getSurefireReportsFile("TEST-jira2117.NestedDisplayNameTest$B$C.xml", UTF_8)
86                  .assertContainsText("<testcase name=\"Display name of non-parameterized level 2 test method\" "
87                          + "classname=\"" + expectedDisplayNameForNestedClassC + "\"")
88                  .assertContainsText(
89                          "<testcase name=\"Display name of parameterized level 2 test method[1] paramValue1\" "
90                                  + "classname=\"" + expectedDisplayNameForNestedClassC + "\"")
91                  .assertContainsText(
92                          "<testcase name=\"Display name of parameterized level 2 test method[2] paramValue2\" "
93                                  + "classname=\"" + expectedDisplayNameForNestedClassC + "\"");
94      }
95  }