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.SurefireJUnit4IntegrationTestCase;
23  import org.apache.maven.surefire.its.fixture.SurefireLauncher;
24  import org.junit.Test;
25  
26  /**
27   * Test project using "groups" support
28   *
29   * @author <a href="mailto:todd@apache.org">Todd Lipcon</a>
30   * @author <a href="mailto:krosenvold@apache.org">Kristian Rosenvold</a>
31   */
32  public class JUnit48TestCategoriesIT
33          extends SurefireJUnit4IntegrationTestCase
34  {
35      @Test
36      public void testCategoriesAB()
37      {
38          runAB( unpacked() );
39      }
40  
41      @Test
42      public void testCategoriesABForkAlways()
43      {
44          runAB( unpacked().forkAlways() );
45      }
46  
47      @Test
48      public void testCategoriesACFullyQualifiedClassName()
49      {
50          runACFullyQualifiedClassName( unpacked() );
51      }
52  
53      @Test
54      public void testCategoriesACFullyQualifiedClassNameForkAlways()
55      {
56          runACFullyQualifiedClassName( unpacked().forkAlways() );
57      }
58  
59      @Test
60      public void testCategoriesACClassNameSuffix()
61      {
62          runACClassNameSuffix( unpacked() );
63      }
64  
65      @Test
66      public void testCategoriesACClassNameSuffixForkAlways()
67      {
68          runACClassNameSuffix( unpacked().forkAlways() );
69      }
70  
71      @Test
72      public void testCategoriesBadCategory()
73      {
74          runBadCategory( unpacked() );
75      }
76  
77      @Test
78      public void testBadCategoryForkAlways()
79      {
80          runBadCategory( unpacked().forkAlways() );
81      }
82  
83      private static void runAB( SurefireLauncher unpacked )
84      {
85          unpacked.executeTest()
86                  .verifyErrorFreeLog()
87                  .assertTestSuiteResults( 3, 0, 0, 0 )
88                  .verifyTextInLog( "catA: 1" )
89                  .verifyTextInLog( "catB: 1" )
90                  .verifyTextInLog( "catC: 0" )
91                  .verifyTextInLog( "catNone: 0" );
92      }
93  
94      private static void runACClassNameSuffix( SurefireLauncher unpacked )
95      {
96          unpacked.groups( "CategoryA,CategoryC" )
97                  .executeTest()
98                  .verifyErrorFreeLog()
99                  .assertTestSuiteResults( 6, 0, 0, 0 )
100                 .verifyTextInLog( "catA: 1" )
101                 .verifyTextInLog( "catB: 0" )
102                 .verifyTextInLog( "catC: 1" )
103                 .verifyTextInLog( "catNone: 0" )
104                 .verifyTextInLog( "mA: 1" )
105 
106                 // This seems questionable !? The class is annotated with category C and method with B
107                 .verifyTextInLog( "mB: 1" )
108 
109                 .verifyTextInLog( "mC: 1" )
110                 .verifyTextInLog( "CatNone: 1" );
111     }
112 
113     private static void runACFullyQualifiedClassName( SurefireLauncher unpacked )
114     {
115         unpacked.groups( "junit4.CategoryA,junit4.CategoryC" )
116                 .executeTest()
117                 .verifyErrorFreeLog()
118                 .assertTestSuiteResults( 6, 0, 0, 0 )
119                 .verifyTextInLog( "catA: 1" )
120                 .verifyTextInLog( "catB: 0" )
121                 .verifyTextInLog( "catC: 1" )
122                 .verifyTextInLog( "catNone: 0" )
123                 .verifyTextInLog( "mA: 1" )
124 
125                 // This seems questionable !? The class is annotated with category C and method with B
126                 .verifyTextInLog( "mB: 1" )
127 
128                 .verifyTextInLog( "mC: 1" )
129                 .verifyTextInLog( "CatNone: 1" );
130     }
131 
132     private static void runBadCategory( SurefireLauncher unpacked )
133     {
134         unpacked.failIfNoTests( false )
135                 .groups( "BadCategory" )
136                 .executeTest()
137                 .verifyErrorFreeLog();
138     }
139 
140     private SurefireLauncher unpacked()
141     {
142         return unpack( "/junit48-categories" );
143         // .debugSurefireFork();
144     }
145 }