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.OutputValidator;
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.util.Collections;
28  import java.util.HashMap;
29  import java.util.Map;
30  import java.util.Map.Entry;
31  
32  /**
33   * Test project using -Dtest=mtClass#myMethod
34   *
35   * @author Olivier Lamy
36   */
37  public class TestMethodPatternIT
38      extends SurefireJUnit4IntegrationTestCase
39  {
40      private static final String RUNNING_WITH_PROVIDER47 = "parallel='none', perCoreThreadCount=true, threadCount=0";
41  
42      public OutputValidator runMethodPattern( String projectName, Map<String, String> props, String... goals )
43      {
44          SurefireLauncher launcher = unpack( projectName );
45          for ( Entry<String, String> entry : props.entrySet() )
46          {
47              launcher.sysProp( entry.getKey(), entry.getValue() );
48          }
49          for ( String goal : goals )
50          {
51              launcher.addGoal( goal );
52          }
53          return launcher.showErrorStackTraces().debugLogging()
54              .executeTest()
55              .assertTestSuiteResults( 2, 0, 0, 0 );
56      }
57  
58      @Test
59      public void testJUnit44()
60      {
61          runMethodPattern( "junit44-method-pattern", Collections.<String, String>emptyMap() );
62      }
63  
64      @Test
65      public void testJUnit48Provider4()
66      {
67          runMethodPattern( "junit48-method-pattern", Collections.<String, String>emptyMap(), "-P surefire-junit4" );
68      }
69  
70      @Test
71      public void testJUnit48Provider47()
72      {
73          runMethodPattern( "junit48-method-pattern", Collections.<String, String>emptyMap(), "-P surefire-junit47" )
74              .verifyTextInLog( RUNNING_WITH_PROVIDER47 );
75      }
76  
77      @Test
78      public void testJUnit48WithCategoryFilter()
79      {
80          unpack( "junit48-method-pattern" )
81              .addGoal( "-Dgroups=junit4.SampleCategory" )
82              .executeTest()
83              .assertTestSuiteResults( 1, 0, 0, 0 );
84      }
85  
86      @Test
87      public void testTestNgMethodBefore()
88      {
89          Map<String, String> props = new HashMap<>();
90          props.put( "testNgVersion", "5.7" );
91          props.put( "testNgClassifier", "jdk15" );
92          runMethodPattern( "testng-method-pattern-before", props );
93      }
94  
95      @Test
96      public void testTestNGMethodPattern()
97      {
98          Map<String, String> props = new HashMap<>();
99          props.put( "testNgVersion", "5.7" );
100         props.put( "testNgClassifier", "jdk15" );
101         runMethodPattern( "/testng-method-pattern", props );
102     }
103 
104     @Test
105     public void testMethodPatternAfter()
106     {
107         unpack( "testng-method-pattern-after" )
108                 .sysProp( "testNgVersion", "5.7" )
109                 .sysProp( "testNgClassifier", "jdk15" )
110                 .executeTest()
111                 .verifyErrorFree( 2 )
112                 .verifyTextInLog( "Called tearDown" );
113     }
114 
115 }