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" ).executeTest().verifyErrorFreeLog().assertTestSuiteResults( 2, 0, 0, 0 );
45      }
46  
47      /**
48       * Runs two tests encapsulated in a suite
49       */
50      @Test
51      public void testTwoTestCaseSuite()
52          throws Exception
53      {
54          final OutputValidator outputValidator = unpack( "junit-twoTestCaseSuite" ).executeTest();
55          outputValidator.verifyErrorFreeLog().assertTestSuiteResults( 2, 0, 0, 0 );
56          List<ReportTestSuite> reports = HelperAssertions.extractReports( outputValidator.getBaseDir() );
57          Set<String> classNames = extractClassNames( reports );
58          assertContains( classNames, "junit.twoTestCaseSuite.BasicTest" );
59          assertContains( classNames, "junit.twoTestCaseSuite.TestTwo" );
60          assertEquals( "wrong number of classes", 2, classNames.size() );
61          IntegrationTestSuiteResults results = HelperAssertions.parseReportList( reports );
62          HelperAssertions.assertTestSuiteResults( 2, 0, 0, 0, results );
63      }
64  
65      private void assertContains( Set<String> set, String expected )
66      {
67          if ( set.contains( expected ) )
68          {
69              return;
70          }
71          fail( "Set didn't contain " + expected );
72      }
73  
74      private Set<String> extractClassNames( List<ReportTestSuite> reports )
75      {
76          HashSet<String> classNames = new HashSet<String>();
77          for ( ReportTestSuite suite : reports )
78          {
79              classNames.add( suite.getFullClassName() );
80          }
81          return classNames;
82      }
83  
84      @Test
85      public void testJunit4Suite()
86          throws Exception
87      {
88          final OutputValidator outputValidator = unpack( "junit4-twoTestCaseSuite" ).executeTest();
89          outputValidator.verifyErrorFreeLog().assertTestSuiteResults( 2, 0, 0, 0 );
90  
91          List<ReportTestSuite> reports =
92              HelperAssertions.extractReports( outputValidator.getBaseDir() );
93          Set<String> classNames = extractClassNames( reports );
94          assertContains( classNames, "twoTestCaseSuite.BasicTest" );
95          assertContains( classNames, "twoTestCaseSuite.Junit4TestTwo" );
96          assertEquals( "wrong number of classes", 2, classNames.size() );
97          IntegrationTestSuiteResults results = HelperAssertions.parseReportList( reports );
98          HelperAssertions.assertTestSuiteResults( 2, 0, 0, 0, results );
99      }
100 
101     @Test
102     public void testTestNGSuite()
103         throws Exception
104     {
105         final OutputValidator outputValidator = unpack( "testng-twoTestCaseSuite" ).executeTest();
106         outputValidator.verifyErrorFreeLog().assertTestSuiteResults( 2, 0, 0, 0 );
107         List<ReportTestSuite> reports = HelperAssertions.extractReports( outputValidator.getBaseDir() );
108         Set<String> classNames = extractClassNames( reports );
109         assertContains( classNames, "testng.two.TestNGTestTwo" );
110         assertContains( classNames, "testng.two.TestNGSuiteTest" );
111         assertEquals( "wrong number of classes", 2, classNames.size() );
112         IntegrationTestSuiteResults results = HelperAssertions.parseReportList( reports );
113         HelperAssertions.assertTestSuiteResults( 2, 0, 0, 0, results );
114     }
115 
116 }