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 TestSingleMethodIT
33      extends SurefireJUnit4IntegrationTestCase
34  {
35      private static final String RUNNING_WITH_PROVIDER47 = "parallel='none', perCoreThreadCount=true, threadCount=0";
36  
37      public OutputValidator singleMethod( String projectName, String testToRun, String... goals )
38          throws Exception
39      {
40          SurefireLauncher launcher = unpack( projectName );
41          for ( String goal : goals )
42          {
43              launcher.addGoal( goal );
44          }
45          launcher.showErrorStackTraces().debugLogging();
46          if ( testToRun != null )
47          {
48              launcher.setTestToRun( testToRun );
49          }
50          return launcher.executeTest()
51                  .verifyErrorFreeLog()
52                  .assertTestSuiteResults( 1, 0, 0, 0 );
53      }
54  
55      @Test
56      public void testJunit44()
57          throws Exception
58      {
59          singleMethod( "junit44-single-method", null );
60      }
61  
62      @Test
63      public void testJunit48Provider4()
64          throws Exception
65      {
66          singleMethod( "junit48-single-method", null, "-P surefire-junit4" );
67      }
68  
69      @Test
70      public void testJunit48Provider47()
71          throws Exception
72      {
73          singleMethod( "junit48-single-method", null, "-P surefire-junit47" )
74              .verifyTextInLog( RUNNING_WITH_PROVIDER47 );
75      }
76  
77      @Test
78      public void testJunit48parallel()
79          throws Exception
80      {
81          unpack( "junit48-single-method" )
82              .parallel( "all" )
83              .useUnlimitedThreads()
84              .executeTest()
85              .verifyErrorFreeLog()
86              .assertTestSuiteResults( 1, 0, 0, 0 );
87      }
88  
89      @Test
90      public void testTestNg()
91          throws Exception
92      {
93          singleMethod( "testng-single-method", null );
94      }
95  
96      @Test
97      public void testTestNg5149()
98          throws Exception
99      {
100         singleMethod( "/testng-single-method-5-14-9", null );
101     }
102 
103     @Test
104     public void fullyQualifiedJunit48Provider4()
105             throws Exception
106     {
107         singleMethod( "junit48-single-method", "junit4.BasicTest#testSuccessOne", "-P surefire-junit4" );
108     }
109 
110     @Test
111     public void fullyQualifiedJunit48Provider47()
112             throws Exception
113     {
114         singleMethod("junit48-single-method", "junit4.BasicTest#testSuccessOne", "-P surefire-junit47");
115     }
116 
117     @Test
118     public void fullyQualifiedTestNg()
119             throws Exception
120     {
121         singleMethod( "testng-single-method", "testng.BasicTest#testSuccessOne" );
122     }
123 
124 }