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  
31  /**
32   * Test project using -Dtest=mtClass#myMethod
33   *
34   * @author Olivier Lamy
35   */
36  public class TestSingleMethodIT
37      extends SurefireJUnit4IntegrationTestCase
38  {
39      private static final String RUNNING_WITH_PROVIDER47 = "parallel='none', perCoreThreadCount=true, threadCount=0";
40  
41      public OutputValidator singleMethod( String projectName, Map<String, String> props, String testToRun,
42                                           String... goals )
43          throws Exception
44      {
45          SurefireLauncher launcher = unpack( projectName );
46          for ( Map.Entry<String, String> entry : props.entrySet() )
47          {
48              launcher.sysProp( entry.getKey(), entry.getValue() );
49          }
50          for ( String goal : goals )
51          {
52              launcher.addGoal( goal );
53          }
54          launcher.showErrorStackTraces().debugLogging();
55          if ( testToRun != null )
56          {
57              launcher.setTestToRun( testToRun );
58          }
59          return launcher.executeTest()
60                  .verifyErrorFreeLog()
61                  .assertTestSuiteResults( 1, 0, 0, 0 );
62      }
63  
64      @Test
65      public void testJunit44()
66          throws Exception
67      {
68          singleMethod( "junit44-single-method", Collections.<String, String>emptyMap(), null );
69      }
70  
71      @Test
72      public void testJunit48Provider4()
73          throws Exception
74      {
75          singleMethod( "junit48-single-method", Collections.<String, String>emptyMap(), null, "-P surefire-junit4" );
76      }
77  
78      @Test
79      public void testJunit48Provider47()
80          throws Exception
81      {
82          singleMethod( "junit48-single-method", Collections.<String, String>emptyMap(), null, "-P surefire-junit47" )
83              .verifyTextInLog( RUNNING_WITH_PROVIDER47 );
84      }
85  
86      @Test
87      public void testJunit48parallel()
88          throws Exception
89      {
90          unpack( "junit48-single-method" )
91              .parallel( "all" )
92              .useUnlimitedThreads()
93              .executeTest()
94              .verifyErrorFreeLog()
95              .assertTestSuiteResults( 1, 0, 0, 0 );
96      }
97  
98      @Test
99      public void testTestNg()
100         throws Exception
101     {
102         Map<String, String> props = new HashMap<>();
103         props.put( "testNgVersion", "5.7" );
104         props.put( "testNgClassifier", "jdk15" );
105         singleMethod( "testng-single-method", props, null );
106     }
107 
108     @Test
109     public void testTestNg5149()
110         throws Exception
111     {
112         singleMethod( "/testng-single-method-5-14-9", Collections.<String, String>emptyMap(), null );
113     }
114 
115     @Test
116     public void fullyQualifiedJunit48Provider4()
117             throws Exception
118     {
119         singleMethod( "junit48-single-method", Collections.<String, String>emptyMap(),
120                             "junit4.BasicTest#testSuccessOne", "-P surefire-junit4" );
121     }
122 
123     @Test
124     public void fullyQualifiedJunit48Provider47()
125             throws Exception
126     {
127         singleMethod("junit48-single-method", Collections.<String, String>emptyMap(),
128                             "junit4.BasicTest#testSuccessOne", "-P surefire-junit47");
129     }
130 
131     @Test
132     public void fullyQualifiedTestNg()
133             throws Exception
134     {
135         Map<String, String> props = new HashMap<>();
136         props.put( "testNgVersion", "5.7" );
137         props.put( "testNgClassifier", "jdk15" );
138         singleMethod( "testng-single-method", props, "testng.BasicTest#testSuccessOne" );
139     }
140 
141 }