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