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