View Javadoc

1   package org.apache.maven.surefire.its;
2   /*
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   */
20  
21  
22  import org.apache.maven.it.VerificationException;
23  import org.apache.maven.it.Verifier;
24  import org.apache.maven.it.util.ResourceExtractor;
25  import org.apache.maven.surefire.its.misc.HelperAssertions;
26  
27  import java.io.File;
28  import java.io.IOException;
29  import java.util.ArrayList;
30  import java.util.Arrays;
31  import java.util.List;
32  
33  /**
34   * Verifies that the providers get the result summary at the bottom of the run correctly, in different forkmodes
35   * SUREFIRE-613 Asserts proper test counts when running in parallel
36   *
37   * @author Kristian Rosenvold
38   */
39  public class ResultCountingIT
40      extends AbstractSurefireIntegrationTestClass
41  {
42      public void testCountingWithJunit481ForkNever()
43          throws Exception
44      {
45          assertForkMode( "never" );
46      }
47  
48      public void testCountingWithJunit481ForkOnce()
49          throws Exception
50      {
51          assertForkMode( "once" );
52      }
53  
54  
55      public void testCountingWithJunit481ForkAlways()
56          throws Exception
57      {
58          assertForkMode( "always" );
59      }
60  
61      private void assertForkMode( String forkMode )
62          throws IOException, VerificationException
63      {
64          File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/result-counting" );
65  
66          Verifier verifier = new Verifier( testDir.getAbsolutePath() );
67          String[] opts = { "-fn" };
68          verifier.setCliOptions( new ArrayList<String>( Arrays.asList( opts ) ) );
69          List<String> goals = getGoals( forkMode );
70          this.executeGoals( verifier, goals );
71  
72          verifier.resetStreams();
73  
74          HelperAssertions.assertTestSuiteResults( 36, 23, 4, 2, testDir );
75  
76          verifier.verifyTextInLog( "Tests run: 36, Failures: 4, Errors: 23, Skipped: 2" );
77      }
78  
79      private List<String> getGoals( String forkMode )
80      {
81          List<String> goals = this.getInitialGoals();
82          goals.add( "test" );
83          goals.add( "-DforkMode=" + forkMode );
84          return goals;
85      }
86  }