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;
20  
21  import java.util.List;
22  
23  import org.apache.maven.plugins.surefire.report.ReportTestSuite;
24  import org.apache.maven.surefire.its.fixture.HelperAssertions;
25  import org.apache.maven.surefire.its.fixture.OutputValidator;
26  import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase;
27  import org.apache.maven.surefire.its.fixture.SurefireLauncher;
28  import org.junit.Ignore;
29  import org.junit.Test;
30  
31  import static org.junit.Assert.assertEquals;
32  import static org.junit.Assert.assertTrue;
33  
34  /**
35   * Basic suite test using all known versions of TestNG. Used for regression testing Surefire against old versions. To
36   * check new versions of TestNG work with current versions of Surefire, instead run the full test suite with
37   * -Dtestng.version=5.14.2 (for example)
38   *
39   * @author <a href="mailto:dfabulich@apache.org">Dan Fabulich</a>
40   * @author <a href="mailto:krosenvold@apache.org">Kristian Rosenvold</a>
41   */
42  public class CheckTestNgVersionsIT extends SurefireJUnit4IntegrationTestCase {
43  
44      @Test
45      public void test47() {
46          runTestNgTest("4.7", "jdk15");
47      }
48  
49      @Test
50      @Ignore("5.0 and 5.0.1 jars on central are malformed SUREFIRE-375 + MAVENUPLOAD-1024")
51      public void xXXtest50() {
52          runTestNgTest("5.0", "jdk15");
53      }
54  
55      @Test
56      @Ignore("5.0 and 5.0.1 jars on central are malformed SUREFIRE-375 + MAVENUPLOAD-1024")
57      public void xXXtest501() {
58          runTestNgTest("5.0.1", "jdk15");
59      }
60  
61      @Test
62      public void test502() {
63          runTestNgTest("5.0.2", "jdk15");
64      }
65  
66      @Test
67      public void test51() {
68          runTestNgTest("5.1", "jdk15");
69      }
70  
71      @Test
72      public void test55() {
73          runTestNgTest("5.5", "jdk15");
74      }
75  
76      @Test
77      public void test56() {
78          runTestNgTest("5.6", "jdk15");
79      }
80  
81      @Test
82      public void test57() {
83          runTestNgTest("5.7", "jdk15");
84      }
85  
86      @Test
87      public void test58() {
88          runTestNgTest("5.8", "jdk15");
89      }
90  
91      @Test
92      public void test59() {
93          runTestNgTest("5.9", "jdk15");
94      }
95  
96      @Test
97      public void test510() {
98          runTestNgTest("5.10", "jdk15");
99      }
100 
101     @Test
102     public void test511() {
103         runTestNgTest("5.11", "jdk15");
104     }
105 
106     @Test
107     public void test512() {
108         runTestNgTest("5.12.1");
109     }
110 
111     @Test
112     public void test513() {
113         runTestNgTest("5.13");
114     }
115 
116     @Test
117     public void test5131() {
118         runTestNgTest("5.13.1");
119     }
120 
121     @Test
122     public void test514() {
123         runTestNgTest("5.14");
124     }
125 
126     @Test
127     public void test5141() {
128         runTestNgTest("5.14.1");
129     }
130 
131     @Test
132     public void test5142() {
133         runTestNgTest("5.14.2");
134     }
135 
136     @Test
137     public void test60() {
138         runTestNgTest("6.0");
139     }
140 
141     @Test
142     public void test685() {
143         runTestNgTestWithRunOrder("6.8.5");
144     }
145 
146     private void runTestNgTestWithRunOrder(String version) {
147         runTestNgTest(version, null, true);
148     }
149 
150     private void runTestNgTest(String version) {
151         runTestNgTest(version, null, false);
152     }
153 
154     private void runTestNgTest(String version, String classifier) {
155         runTestNgTest(version, classifier, false);
156     }
157 
158     private void runTestNgTest(String version, String classifier, boolean validateRunOrder) {
159         final SurefireLauncher launcher = unpack("testng-simple").sysProp("testNgVersion", version);
160 
161         if (classifier != null) {
162             launcher.sysProp("testNgClassifier", classifier);
163         }
164 
165         final OutputValidator outputValidator = launcher.executeTest();
166 
167         outputValidator.assertTestSuiteResults(3, 0, 0, 0);
168 
169         if (validateRunOrder) {
170             // assert correct run order of tests
171             List<ReportTestSuite> report = HelperAssertions.extractReports(outputValidator.getBaseDir());
172 
173             assertEquals(3, report.size());
174 
175             assertTrue(
176                     "TestNGSuiteTestC was executed first",
177                     getTestClass(report, 0).endsWith("TestNGSuiteTestC"));
178 
179             assertTrue(
180                     "TestNGSuiteTestB was executed second",
181                     getTestClass(report, 1).endsWith("TestNGSuiteTestB"));
182 
183             assertTrue(
184                     "TestNGSuiteTestA was executed last",
185                     getTestClass(report, 2).endsWith("TestNGSuiteTestA"));
186         }
187     }
188 
189     private String getTestClass(List<ReportTestSuite> report, int i) {
190         return report.get(i).getFullClassName();
191     }
192 }