1 package org.apache.maven.surefire.its.jiras;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.FileNotFoundException;
23
24 import org.apache.maven.shared.utils.xml.Xpp3Dom;
25 import org.apache.maven.shared.utils.xml.Xpp3DomBuilder;
26 import org.apache.maven.surefire.its.fixture.OutputValidator;
27 import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase;
28 import org.junit.Assert;
29 import org.junit.Test;
30
31 public class Surefire943ReportContentIT
32 extends SurefireJUnit4IntegrationTestCase
33 {
34
35 @Test
36 public void test_noParallel()
37 throws Exception
38 {
39 doTest( "none" );
40 }
41
42 @Test
43 public void test_parallelBoth()
44 throws Exception
45 {
46 doTest( "both" );
47 }
48
49 private void doTest( String parallelMode )
50 throws Exception
51 {
52 OutputValidator validator =
53 unpack( "surefire-943-report-content" ).maven()
54 .sysProp( "parallel", parallelMode )
55 .sysProp( "threadCount", 4 )
56 .withFailure().executeTest();
57
58 validator.assertTestSuiteResults( 10, 1, 3, 3 );
59
60 validate( validator, "org.sample.module.My1Test", 1 );
61 validate( validator, "org.sample.module.My2Test", 1 );
62 validate( validator, "org.sample.module.My3Test", 0 );
63 validateSkipped( validator, "org.sample.module.My4Test" );
64 validateFailInBeforeClass( validator, "org.sample.module.My5Test" );
65 }
66
67 private void validateFailInBeforeClass( OutputValidator validator, String className )
68 throws FileNotFoundException
69 {
70 Xpp3Dom[] children = readTests( validator, className );
71
72 Assert.assertEquals( 1, children.length );
73
74 Xpp3Dom child = children[0];
75
76 Assert.assertEquals( className, child.getAttribute( "classname" ) );
77 Assert.assertEquals( className, child.getAttribute( "name" ) );
78
79 Assert.assertEquals( "Expected error tag for failed BeforeClass method for " + className, 1,
80 child.getChildren( "error" ).length );
81
82 Assert.assertTrue( "time for test failure in BeforeClass is expected to be positive",
83 Double.compare( Double.parseDouble( child.getAttribute( "time" ) ), 0.0d ) >= 0 );
84
85 Assert.assertTrue( "time for test failure in BeforeClass is expected to be resonably low",
86 Double.compare( Double.parseDouble( child.getAttribute( "time" ) ), 2.0d ) <= 0 );
87
88 }
89
90 private void validateSkipped( OutputValidator validator, String className )
91 throws FileNotFoundException
92 {
93 Xpp3Dom[] children = readTests( validator, className );
94
95 Assert.assertEquals( 1, children.length );
96
97 Xpp3Dom child = children[0];
98
99 Assert.assertEquals( className, child.getAttribute( "classname" ) );
100 Assert.assertEquals( className, child.getAttribute( "name" ) );
101
102 Assert.assertEquals( "Expected skipped tag for ignored method for " + className, 1,
103 child.getChildren( "skipped" ).length );
104
105 Assert.assertTrue( "time for ignored test is expected to be zero",
106 Double.compare( Double.parseDouble( child.getAttribute( "time" ) ), 0.0d ) == 0 );
107 }
108
109 private void validate( OutputValidator validator, String className, int ignored )
110 throws FileNotFoundException
111 {
112 Xpp3Dom[] children = readTests( validator, className );
113
114 Assert.assertEquals( 2 + ignored, children.length );
115
116 for ( Xpp3Dom child : children )
117 {
118 Assert.assertEquals( className, child.getAttribute( "classname" ) );
119
120 if ( "alwaysSuccessful".equals( child.getAttribute( "name" ) ) )
121 {
122 Assert.assertEquals( "Expected no failures for method alwaysSuccessful for " + className, 0,
123 child.getChildCount() );
124
125 Assert.assertTrue( "time for successful test is expected to be positive",
126 Double.compare( Double.parseDouble( child.getAttribute( "time" ) ), 0.0d ) > 0 );
127 }
128 else if ( child.getAttribute( "name" ).contains( "Ignored" ) )
129 {
130 Assert.assertEquals( "Expected skipped-tag for ignored method for " + className, 1,
131 child.getChildren( "skipped" ).length );
132
133 Assert.assertTrue( "time for ignored test is expected to be zero",
134 Double.compare( Double.parseDouble( child.getAttribute( "time" ) ), 0.0d ) == 0 );
135
136 }
137 else
138 {
139 Assert.assertEquals( "Expected methods \"alwaysSuccessful\", \"*Ignored\" and \"fails\" in "
140 + className, "fails", child.getAttribute( "name" ) );
141 Assert.assertEquals( "Expected failure description for method \"fails\" in " + className, 1,
142 child.getChildren( "failure" ).length );
143 Assert.assertTrue( "time for failed test is expected to be positive",
144 Double.compare( Double.parseDouble( child.getAttribute( "time" ) ), 0.0d ) > 0 );
145 }
146 }
147 }
148
149 private Xpp3Dom[] readTests( OutputValidator validator, String className )
150 throws FileNotFoundException
151 {
152 Xpp3Dom testResult =
153 Xpp3DomBuilder.build( validator.getSurefireReportsXmlFile( "TEST-" + className + ".xml" ).getFileInputStream(),
154 "UTF-8" );
155 Xpp3Dom[] children = testResult.getChildren( "testcase" );
156 return children;
157 }
158
159 }