File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\test\src\test\java\hudson\tasks\junit\SuiteResultTest.java.html

1 /*
2 * The MIT License
3 *
4 * Copyright 2012 Jesse Glick.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24
25 package hudson.tasks.junit;
26
27 import edu.umd.cs.findbugs.annotations.SuppressWarnings;
28 import java.io.File;
29 import java.io.FileWriter;
30 import java.io.PrintWriter;
31 import java.io.Writer;
32 import java.util.List;
33 import static org.jvnet.hudson.test.MemoryAssert.*;
34 import static org.junit.Assert.*;
35 import org.junit.Test;
36
37 public class SuiteResultTest {
38
39 @SuppressWarnings({"DM_DEFAULT_ENCODING", "OS_OPEN_STREAM", "RV_RETURN_VALUE_IGNORED_BAD_PRACTICE"})
40 @Test public void sizeSurefire() throws Exception {
41 File data = File.createTempFile("TEST-", ".xml");
42 try {
43 Writer w = new FileWriter(data);
44 try {
45 PrintWriter pw = new PrintWriter(w);
46 pw.println("<testsuites name='x'>");
47 pw.println("<testsuite failures='10' errors='0' tests='20' name='x'>");
48 // Simulating Surefire 2.12.4 with redirectTestOutputToFile=true:
49 for (int i = 0; i < 10; i++) { // these pass and SF omits stdio
50 pw.println("<testcase name='t" + i + "' classname='x'/>");
51 }
52 for (int i = 10; i < 20; i++) { // these fail and SF includes per-test stdio
53 pw.println("<testcase name='t" + i + "' classname='x'>");
54 pw.println("<failure type='java.lang.AssertionError'>some stack trace</failure>");
55 pw.print("<system-out>");
56 for (int j = 0; j < 1000; j++) {
57 pw.println("t" + i + " out #" + j);
58 }
59 pw.println("</system-out>");
60 pw.print("<system-err>");
61 for (int j = 0; j < 1000; j++) {
62 pw.println("t" + i + " err #" + j);
63 }
64 pw.println("</system-err>");
65 pw.println("</testcase>");
66 }
67 pw.println("</testsuite>");
68 pw.println("</testsuites>");
69 pw.flush();
70 } finally {
71 w.close();
72 }
73 File data2 = new File(data.getParentFile(), data.getName().replaceFirst("^TEST-(.+)[.]xml$", "$1-output.txt"));
74 try {
75 w = new FileWriter(data2);
76 try {
77 PrintWriter pw = new PrintWriter(w);
78 for (int i = 0; i < 20; i++) { // stdio for complete suite (incl. passing tests)
79 for (int j = 0; j < 1000; j++) {
80 pw.println("t" + i + " out #" + j);
81 pw.println("t" + i + " err #" + j);
82 }
83 }
84 pw.flush();
85 } finally {
86 w.close();
87 }
88 SuiteResult sr = parseOne(data);
89 assertHeapUsage(sr, 1100 + /* Unicode overhead */2 * (int) (/*259946*/data.length() + /*495600*/data2.length() + /* SuiteResult.file */data.getAbsolutePath().length()));
90 // XXX serialize using TestResultAction.XSTREAM and verify that round-tripped object has same size
91 } finally {
92 data2.delete();
93 }
94 } finally {
95 data.delete();
96 }
97 }
98
99 private SuiteResult parseOne(File file) throws Exception {
100 List<SuiteResult> results = SuiteResult.parse(file, false);
101 assertEquals(1,results.size());
102 return results.get(0);
103 }
104
105 }
106