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 import org.apache.maven.it.Verifier;
22 import org.apache.maven.it.util.ResourceExtractor;
23 import org.apache.maven.surefire.its.misc.HelperAssertions;
24 import org.apache.maven.surefire.its.misc.ReportTestSuite;
25
26 import java.io.File;
27 import java.util.HashSet;
28 import java.util.List;
29 import java.util.Set;
30
31
32
33
34
35
36 public class TwoTestCasesIT
37 extends AbstractSurefireIntegrationTestClass
38 {
39 public void testTwoTestCases()
40 throws Exception
41 {
42 File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/junit-twoTestCases" );
43
44 Verifier verifier = new Verifier( testDir.getAbsolutePath() );
45 this.executeGoal( verifier, "test" );
46 verifier.verifyErrorFreeLog();
47 verifier.resetStreams();
48
49 HelperAssertions.assertTestSuiteResults( 2, 0, 0, 0, testDir );
50 }
51
52
53
54
55 public void testTwoTestCaseSuite()
56 throws Exception
57 {
58 File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/junit-twoTestCaseSuite" );
59
60 Verifier verifier = new Verifier( testDir.getAbsolutePath() );
61 this.executeGoal( verifier, "test" );
62 verifier.verifyErrorFreeLog();
63 verifier.resetStreams();
64 List<ReportTestSuite> reports = HelperAssertions.extractReports( ( new File[]{ testDir } ) );
65 Set<String> classNames = extractClassNames( reports );
66 assertContains( classNames, "junit.twoTestCaseSuite.BasicTest" );
67 assertContains( classNames, "junit.twoTestCaseSuite.TestTwo" );
68 assertEquals( "wrong number of classes", 2, classNames.size() );
69 IntegrationTestSuiteResults results = HelperAssertions.parseReportList( reports );
70 HelperAssertions.assertTestSuiteResults( 2, 0, 0, 0, results );
71 }
72
73 private void assertContains( Set<String> set, String expected )
74 {
75 if ( set.contains( expected ) )
76 {
77 return;
78 }
79 fail( "Set didn't contain " + expected );
80 }
81
82 private Set<String> extractClassNames( List<ReportTestSuite> reports )
83 {
84 HashSet<String> classNames = new HashSet<String>();
85 for ( ReportTestSuite suite : reports )
86 {
87 classNames.add( suite.getFullClassName() );
88 }
89 return classNames;
90 }
91
92 public void testJunit4Suite()
93 throws Exception
94 {
95 File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/junit4-twoTestCaseSuite" );
96
97 Verifier verifier = new Verifier( testDir.getAbsolutePath() );
98 this.executeGoal( verifier, "test" );
99 verifier.verifyErrorFreeLog();
100 verifier.resetStreams();
101
102 List<ReportTestSuite> reports = HelperAssertions.extractReports( ( new File[]{ testDir } ) );
103 Set<String> classNames = extractClassNames( reports );
104 assertContains( classNames, "twoTestCaseSuite.BasicTest" );
105 assertContains( classNames, "twoTestCaseSuite.Junit4TestTwo" );
106 assertEquals( "wrong number of classes", 2, classNames.size() );
107 IntegrationTestSuiteResults results = HelperAssertions.parseReportList( reports );
108 HelperAssertions.assertTestSuiteResults( 2, 0, 0, 0, results );
109 }
110
111 public void testTestNGSuite()
112 throws Exception
113 {
114 File testDir = ResourceExtractor.simpleExtractResources( getClass(), "/testng-twoTestCaseSuite" );
115
116 Verifier verifier = new Verifier( testDir.getAbsolutePath() );
117 this.executeGoal( verifier, "test" );
118 verifier.verifyErrorFreeLog();
119 verifier.resetStreams();
120
121 List<ReportTestSuite> reports = HelperAssertions.extractReports( ( new File[]{ testDir } ) );
122 Set<String> classNames = extractClassNames( reports );
123 assertContains( classNames, "testng.two.TestNGTestTwo" );
124 assertContains( classNames, "testng.two.TestNGSuiteTest" );
125 assertEquals( "wrong number of classes", 2, classNames.size() );
126 IntegrationTestSuiteResults results = HelperAssertions.parseReportList( reports );
127 HelperAssertions.assertTestSuiteResults( 2, 0, 0, 0, results );
128 }
129
130 }