View Javadoc
1   package org.apache.maven.surefire.its.jiras;
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.it.VerificationException;
23  import org.apache.maven.surefire.its.fixture.OutputValidator;
24  import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase;
25  import org.apache.maven.surefire.its.fixture.SurefireLauncher;
26  import org.junit.Test;
27  
28  import static org.hamcrest.Matchers.containsString;
29  import static org.hamcrest.Matchers.is;
30  import static org.hamcrest.Matchers.startsWith;
31  
32  /**
33   * IT for https://issues.apache.org/jira/browse/SUREFIRE-1177
34   *
35   * @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
36   * @since 2.19
37   */
38  public class Surefire1177TestngParallelSuitesIT
39      extends SurefireJUnit4IntegrationTestCase
40  {
41      private static final String EXPECTED_LINE = "TestNGSuiteTest#shouldRunAndPrintItself()";
42      private static final String UNEXPECTED_LINE = "ShouldNotRunTest#shouldNotRun()";
43  
44      @Test
45      public void twoSuitesInParallel()
46          throws VerificationException
47      {
48          OutputValidator validator = unpack()
49                  .forkMode( "never" )
50                  .executeTest()
51                  .verifyErrorFree( 2 );
52  
53          validator.assertThatLogLine( startsWith( EXPECTED_LINE ), is( 2 ) );
54          validator.assertThatLogLine( is( EXPECTED_LINE + " 1." ), is( 1 ) );
55          validator.assertThatLogLine( is( EXPECTED_LINE + " 2." ), is( 1 ) );
56          validator.assertThatLogLine( containsString( UNEXPECTED_LINE ), is( 0 ) );
57      }
58  
59      @Test
60      public void twoSuitesInParallelForked()
61              throws VerificationException
62      {
63          OutputValidator validator = unpack()
64                  .forkMode( "once" )
65                  .executeTest()
66                  .verifyErrorFree( 2 );
67  
68          validator.assertThatLogLine( startsWith( EXPECTED_LINE ), is( 2 ) );
69          validator.assertThatLogLine( is( EXPECTED_LINE + " 1." ), is( 1 ) );
70          validator.assertThatLogLine( is( EXPECTED_LINE + " 2." ), is( 1 ) );
71          validator.assertThatLogLine( containsString( UNEXPECTED_LINE ), is( 0 ) );
72      }
73  
74      private SurefireLauncher unpack()
75      {
76          return unpack( "testng-parallel-suites" );
77      }
78  }