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