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.it.VerificationException;
23  import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase;
24  import org.apache.maven.surefire.its.fixture.SurefireLauncher;
25  import org.junit.Test;
26  
27  import java.io.IOException;
28  
29  /**
30   * Test project using "groups" support
31   *
32   * @author <a href="mailto:todd@apache.org">Todd Lipcon</a>
33   * @author <a href="mailto:krosenvold@apache.org">Kristian Rosenvold</a>
34   */
35  public class JUnit48TestCategoriesIT
36      extends SurefireJUnit4IntegrationTestCase
37  {
38      @Test
39      public void testCategoriesAB()
40          throws Exception
41      {
42          runAB( unpacked() );
43      }
44  
45  
46      @Test
47      public void testCategoriesABForkAlways()
48          throws Exception
49      {
50          runAB( unpacked() );
51      }
52  
53      @Test
54      public void testCategoriesAC()
55          throws Exception
56      {
57          runAC( unpacked() );
58      }
59  
60      private void runAB( SurefireLauncher unpacked )
61              throws VerificationException
62      {
63          unpacked.executeTest().verifyErrorFreeLog().assertTestSuiteResults( 3, 0, 0, 0 ).verifyTextInLog(
64                  "catA: 1" ).verifyTextInLog( "catB: 1" ).verifyTextInLog( "catC: 0" ).verifyTextInLog( "catNone: 0" );
65      }
66  
67      @Test
68      public void testCategoriesACForkAlways()
69          throws Exception
70      {
71          runAC( unpacked().forkAlways() );
72      }
73  
74  
75      private void runAC( SurefireLauncher surefireLauncher )
76          throws Exception
77      {
78          surefireLauncher.groups(
79              "junit4.CategoryA,junit4.CategoryC" ).executeTest().verifyErrorFreeLog().assertTestSuiteResults( 6, 0, 0,
80                                                                                                               0 ).verifyTextInLog(
81              "catA: 1" ).verifyTextInLog( "catB: 0" ).verifyTextInLog( "catC: 1" ).verifyTextInLog(
82              "catNone: 0" ).verifyTextInLog( "mA: 1" ).verifyTextInLog(
83              "mB: 1" ) // This seems questionable !? The class is annotated with category C and method with B
84              .verifyTextInLog( "mC: 1" ).verifyTextInLog( "CatNone: 1" );
85      }
86  
87      private SurefireLauncher unpacked()
88          throws VerificationException, IOException
89      {
90          return unpack( "/junit48-categories" ); // .debugSurefireFork();
91      }
92  
93  }