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 org.apache.maven.surefire.its.fixture.MavenLauncher;
23  import org.apache.maven.surefire.its.fixture.OutputValidator;
24  import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase;
25  import org.junit.Test;
26  import org.junit.runner.RunWith;
27  import org.junit.runners.Parameterized;
28  
29  import java.util.HashMap;
30  import java.util.Map;
31  
32  import static org.junit.runners.Parameterized.Parameter;
33  
34  /**
35   * Base test class for SUREFIRE-580, configuration parameter {@code skipAfterFailureCount}.
36   *
37   * @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
38   * @since 2.19
39   */
40  @RunWith( Parameterized.class )
41  public abstract class AbstractFailFastIT
42      extends SurefireJUnit4IntegrationTestCase
43  {
44      @Parameter( 0 )
45      public String description;
46  
47      @Parameter( 1 )
48      public String profile;
49  
50      @Parameter( 2 )
51      public Map<String, String> properties;
52  
53      @Parameter( 3 )
54      public int total;
55  
56      @Parameter( 4 )
57      public int failures;
58  
59      @Parameter( 5 )
60      public int errors;
61  
62      @Parameter( 6 )
63      public int skipped;
64  
65      protected abstract String withProvider();
66  
67      private OutputValidator prepare( String description, String profile, Map<String, String> properties )
68      {
69          MavenLauncher launcher = unpack( "/fail-fast-" + withProvider(), "_" + description )
70              .maven();
71  
72          if ( profile != null )
73          {
74              launcher.addGoal( "-P " + profile );
75          }
76  
77          if ( failures != 0 || errors != 0 )
78          {
79              launcher.withFailure();
80          }
81  
82          return launcher.sysProp( properties ).executeTest();
83      }
84  
85      static Map<String, String> props( int forkCount, int skipAfterFailureCount, boolean reuseForks )
86      {
87          Map<String, String> props = new HashMap<>( 3 );
88          props.put( "surefire.skipAfterFailureCount", "" + skipAfterFailureCount );
89          props.put( "forkCount", "" + forkCount );
90          props.put( "reuseForks", "" + reuseForks );
91          return props;
92      }
93  
94      @Test
95      public void test()
96      {
97          prepare( description, profile, properties )
98              .assertTestSuiteResults( total, errors, failures, skipped );
99      }
100 }