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.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
43      extends SurefireJUnit4IntegrationTestCase
44  {
45  
46      @Test public void test47()
47          throws Exception
48      {
49          runTestNgTest( "4.7" );
50      }
51  
52      @Test @Ignore( "5.0 and 5.0.1 jars on central are malformed SUREFIRE-375 + MAVENUPLOAD-1024" ) public void XXXtest50()
53          throws Exception
54      {
55          runTestNgTest( "5.0" );
56      }
57  
58      @Test @Ignore( "5.0 and 5.0.1 jars on central are malformed SUREFIRE-375 + MAVENUPLOAD-1024" ) public void XXXtest501()
59          throws Exception
60      {
61          runTestNgTest( "5.0.1" );
62      }
63  
64      @Test public void test502()
65          throws Exception
66      {
67          runTestNgTest( "5.0.2" );
68      }
69  
70      @Test public void test51()
71          throws Exception
72      {
73          runTestNgTest( "5.1" );
74      }
75  
76      @Test public void test55()
77          throws Exception
78      {
79          runTestNgTest( "5.5" );
80      }
81  
82      @Test public void test56()
83          throws Exception
84      {
85          runTestNgTest( "5.6" );
86      }
87  
88      @Test public void test57()
89          throws Exception
90      {
91          runTestNgTest( "5.7" );
92      }
93  
94      @Test public void test58()
95          throws Exception
96      {
97          runTestNgTest( "5.8" );
98      }
99  
100     @Test public void test59()
101         throws Exception
102     {
103         runTestNgTest( "5.9" );
104     }
105 
106     @Test public void test510()
107         throws Exception
108     {
109         runTestNgTest( "5.10" );
110     }
111 
112     @Test public void test511()
113         throws Exception
114     {
115         runTestNgTest( "5.11" );
116     }
117 
118     @Test public void test512()
119         throws Exception
120     {
121         runTestNgTest( "5.12.1" );
122     }
123 
124     @Test public void test513()
125         throws Exception
126     {
127         runTestNgTest( "5.13" );
128     }
129 
130     @Test public void test5131()
131         throws Exception
132     {
133         runTestNgTest( "5.13.1" );
134     }
135 
136     @Test public void test514()
137         throws Exception
138     {
139         runTestNgTest( "5.14" );
140     }
141 
142     @Test public void test5141()
143         throws Exception
144     {
145         runTestNgTest( "5.14.1" );
146     }
147 
148     @Test public void test5142()
149         throws Exception
150     {
151         runTestNgTest( "5.14.2" );
152     }
153 
154     @Test public void test60()
155         throws Exception
156     {
157         runTestNgTest( "6.0", false );
158     }
159 
160     @Test public void test685()
161         throws Exception
162     {
163         runTestNgTestWithRunOrder( "6.8.5" );
164     }
165 
166     private void runTestNgTestWithRunOrder( String version )
167         throws Exception
168     {
169         runTestNgTest( version, true );
170     }
171 
172     private void runTestNgTest( String version )
173         throws Exception
174     {
175         runTestNgTest( version, false );
176     }
177 
178     private void runTestNgTest( String version, boolean validateRunOrder )
179         throws Exception
180     {
181 
182         final OutputValidator outputValidator = unpack( "testng-simple" ).resetInitialGoals( version ).executeTest();
183         outputValidator.verifyErrorFreeLog().assertTestSuiteResults( 3, 0, 0, 0 );
184 
185         if ( validateRunOrder )
186         {
187             // assert correct run order of tests
188             List<ReportTestSuite> report = HelperAssertions.extractReports( outputValidator.getBaseDir() );
189 
190             assertEquals( 3, report.size() );
191 
192             assertTrue( "TestNGSuiteTestC was executed first", getTestClass( report, 0 ).endsWith( "TestNGSuiteTestC" ) );
193             assertTrue( "TestNGSuiteTestB was executed second", getTestClass( report, 1 ).endsWith( "TestNGSuiteTestB" ) );
194             assertTrue( "TestNGSuiteTestA was executed last", getTestClass( report, 2 ).endsWith( "TestNGSuiteTestA" ) );
195         }
196     }
197 
198     private String getTestClass( List<ReportTestSuite> report, int i )
199     {
200         return report.get( i ).getFullClassName();
201     }
202 }