1 package org.apache.maven.surefire.its;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
34
35
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<String, String>();
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<String, String>();
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 }