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