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.HashSet;
23  import java.util.List;
24  import java.util.Set;
25  import org.apache.maven.plugins.surefire.report.ReportTestSuite;
26  import org.apache.maven.surefire.its.fixture.*;
27  import org.junit.Test;
28  
29  import static org.junit.Assert.assertEquals;
30  import static org.junit.Assert.fail;
31  
32  /**
33   * Test running two test cases; confirms reporting works correctly
34   *
35   * @author <a href="mailto:dfabulich@apache.org">Dan Fabulich</a>
36   */
37  public class TwoTestCasesIT
38      extends SurefireJUnit4IntegrationTestCase
39  {
40      @Test
41      public void testTwoTestCases()
42          throws Exception
43      {
44          unpack( "junit-twoTestCases" )
45                  .sysProp( "testNgVersion", "5.7" )
46                  .sysProp( "testNgClassifier", "jdk15" )
47                  .executeTest()
48                  .verifyErrorFreeLog()
49                  .assertTestSuiteResults( 2, 0, 0, 0 );
50      }
51  
52      /**
53       * Runs two tests encapsulated in a suite
54       */
55      @Test
56      public void testTwoTestCaseSuite()
57          throws Exception
58      {
59          final OutputValidator outputValidator = unpack( "junit-twoTestCaseSuite" )
60                                                          .sysProp( "testNgVersion", "5.7" )
61                                                          .sysProp( "testNgClassifier", "jdk15" )
62                                                          .executeTest();
63          outputValidator.verifyErrorFreeLog().assertTestSuiteResults( 2, 0, 0, 0 );
64          List<ReportTestSuite> reports = HelperAssertions.extractReports( outputValidator.getBaseDir() );
65          Set<String> classNames = extractClassNames( reports );
66          assertContains( classNames, "junit.twoTestCaseSuite.BasicTest" );
67          assertContains( classNames, "junit.twoTestCaseSuite.TestTwo" );
68          assertEquals( "wrong number of classes", 2, classNames.size() );
69          IntegrationTestSuiteResults results = HelperAssertions.parseReportList( reports );
70          HelperAssertions.assertTestSuiteResults( 2, 0, 0, 0, results );
71      }
72  
73      private void assertContains( Set<String> set, String expected )
74      {
75          if ( set.contains( expected ) )
76          {
77              return;
78          }
79          fail( "Set didn't contain " + expected );
80      }
81  
82      private Set<String> extractClassNames( List<ReportTestSuite> reports )
83      {
84          HashSet<String> classNames = new HashSet<String>();
85          for ( ReportTestSuite suite : reports )
86          {
87              classNames.add( suite.getFullClassName() );
88          }
89          return classNames;
90      }
91  
92      @Test
93      public void testJunit4Suite()
94          throws Exception
95      {
96          final OutputValidator outputValidator = unpack( "junit4-twoTestCaseSuite" )
97                                                          .sysProp( "testNgVersion", "5.7" )
98                                                          .sysProp( "testNgClassifier", "jdk15" )
99                                                          .executeTest();
100         outputValidator.verifyErrorFreeLog().assertTestSuiteResults( 2, 0, 0, 0 );
101 
102         List<ReportTestSuite> reports =
103             HelperAssertions.extractReports( outputValidator.getBaseDir() );
104         Set<String> classNames = extractClassNames( reports );
105         assertContains( classNames, "twoTestCaseSuite.BasicTest" );
106         assertContains( classNames, "twoTestCaseSuite.Junit4TestTwo" );
107         assertEquals( "wrong number of classes", 2, classNames.size() );
108         IntegrationTestSuiteResults results = HelperAssertions.parseReportList( reports );
109         HelperAssertions.assertTestSuiteResults( 2, 0, 0, 0, results );
110     }
111 
112     @Test
113     public void testTestNGSuite()
114         throws Exception
115     {
116         final OutputValidator outputValidator = unpack( "testng-twoTestCaseSuite" )
117                                                         .sysProp( "testNgVersion", "5.7" )
118                                                         .sysProp( "testNgClassifier", "jdk15" )
119                                                         .executeTest();
120         outputValidator.verifyErrorFreeLog().assertTestSuiteResults( 2, 0, 0, 0 );
121         List<ReportTestSuite> reports = HelperAssertions.extractReports( outputValidator.getBaseDir() );
122         Set<String> classNames = extractClassNames( reports );
123         assertContains( classNames, "testng.two.TestNGTestTwo" );
124         assertContains( classNames, "testng.two.TestNGSuiteTest" );
125         assertEquals( "wrong number of classes", 2, classNames.size() );
126         IntegrationTestSuiteResults results = HelperAssertions.parseReportList( reports );
127         HelperAssertions.assertTestSuiteResults( 2, 0, 0, 0, results );
128     }
129 
130 }