View Javadoc

1   package org.apache.maven.surefire.its.jiras;
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  import org.apache.maven.surefire.its.fixture.OutputValidator;
22  import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase;
23  import org.apache.maven.surefire.its.fixture.SurefireLauncher;
24  
25  import org.junit.Test;
26  
27  public class Surefire809GroupExpressionsIT
28      extends SurefireJUnit4IntegrationTestCase
29  {
30      @Test
31      public void categoryAB()
32      {
33          OutputValidator validator = unpackJUnit().groups( "junit4.CategoryA AND junit4.CategoryB" ).executeTest();
34          validator.verifyErrorFreeLog();
35          validator.assertTestSuiteResults( 2, 0, 0, 0 );
36          validator.verifyTextInLog( "catA: 1" );
37          validator.verifyTextInLog( "catB: 1" );
38          validator.verifyTextInLog( "catC: 0" );
39          validator.verifyTextInLog( "catNone: 0" );
40          validator.verifyTextInLog( "mA: 1" );
41          validator.verifyTextInLog( "mB: 1" );
42          validator.verifyTextInLog( "mC: 0" );
43      }
44  
45      @Test
46      public void incorrectJUnitVersions()
47      {
48          unpackJUnit().setJUnitVersion( "4.5" ).groups(
49              "junit4.CategoryA AND junit4.CategoryB" ).maven().withFailure().executeTest();
50      }
51  
52      @Test
53      public void testJUnitRunCategoryNotC()
54      {
55          OutputValidator validator = unpackJUnit().groups( "!junit4.CategoryC" ).executeTest();
56          validator.verifyErrorFreeLog();
57          validator.assertTestSuiteResults( 5, 0, 0, 0 );
58          validator.verifyTextInLog( "catA: 2" );
59          validator.verifyTextInLog( "catB: 2" );
60          validator.verifyTextInLog( "catC: 0" );
61          validator.verifyTextInLog( "catNone: 1" );
62          validator.verifyTextInLog( "NoCategoryTest.CatNone: 1" );
63      }
64  
65      @Test
66      public void testExcludedGroups()
67      {
68          OutputValidator validator = unpackJUnit().setExcludedGroups( "junit4.CategoryC" ).executeTest();
69          validator.verifyErrorFreeLog();
70          validator.assertTestSuiteResults( 5, 0, 0, 0 );
71          validator.verifyTextInLog( "catA: 2" );
72          validator.verifyTextInLog( "catB: 2" );
73          validator.verifyTextInLog( "catC: 0" );
74          validator.verifyTextInLog( "catNone: 1" );
75          validator.verifyTextInLog( "NoCategoryTest.CatNone: 1" );
76      }
77  
78      @Test
79      public void testNGRunCategoryAB()
80      {
81          OutputValidator validator = unpackTestNG().groups( "CategoryA AND CategoryB" ).debugLogging().executeTest();
82          validator.verifyErrorFreeLog();
83          validator.assertTestSuiteResults( 2, 0, 0, 0 );
84          validator.verifyTextInLog( "BasicTest.testInCategoriesAB()" );
85          validator.verifyTextInLog( "CategoryCTest.testInCategoriesAB()" );
86      }
87  
88      @Test
89      public void testNGRunCategoryNotC()
90      {
91          OutputValidator validator = unpackTestNG().groups( "!CategoryC" ).debugLogging().executeTest();
92          validator.verifyErrorFreeLog();
93          validator.assertTestSuiteResults( 8, 0, 0, 0 );
94          validator.verifyTextInLog( "catA: 2" );
95          validator.verifyTextInLog( "catB: 2" );
96          validator.verifyTextInLog( "catC: 0" );
97          validator.verifyTextInLog( "catNone: 1" );
98          validator.verifyTextInLog( "mA: 2" );
99          validator.verifyTextInLog( "mB: 2" );
100         validator.verifyTextInLog( "mC: 0" );
101         validator.verifyTextInLog( "NoCategoryTest.CatNone: 1" );
102     }
103 
104     private SurefireLauncher unpackJUnit()
105     {
106         return unpack( "surefire-809-groupExpr-junit48" );
107     }
108 
109     private SurefireLauncher unpackTestNG()
110     {
111         return unpack( "surefire-809-groupExpr-testng" );
112     }
113 
114 }