xref: /AOO42X/test/testcommon/source/org/openoffice/test/common/CSVReporter.java (revision b0efeae40e43e6d4ccd561d22ec612d42773857b)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 package org.openoffice.test.common;
22 
23 import java.io.File;
24 import java.util.Map.Entry;
25 import java.util.Set;
26 
27 import org.junit.Ignore;
28 import org.junit.runner.Description;
29 import org.junit.runner.Result;
30 import org.junit.runner.notification.Failure;
31 import org.junit.runner.notification.RunListener;
32 
33 public class CSVReporter extends RunListener {
34 
35     private File reportDir = Testspace.getFile("output/result");
36 
37     private File file = null;
38 
39     private String testClassName = null;
40 
41     private long suiteStart = 0;
42 
43     private long failures = 0;
44 
45     private long errors = 0;
46 
47     private long tests = 0;
48 
49     private long ignored = 0;
50 
51     private long testStart = 0;
52 
53     @Override
testStarted(Description description)54     public void testStarted(Description description) throws Exception {
55         System.out.println("testStarted");
56         if (!description.getClassName().equals(testClassName)) {
57             finishSuite();
58             startSuite(description);
59         }
60 
61 
62     }
63 
64     @Override
testAssumptionFailure(Failure failure)65     public void testAssumptionFailure(Failure failure) {
66 
67     }
68 
69     @Override
testFailure(Failure failure)70     public void testFailure(Failure failure) throws Exception {
71         System.out.println("testFailure");
72         if (failure.getException() instanceof AssertionError) {
73             failures++;
74         } else {
75             errors++;
76         }
77     }
78 
79     @Override
testFinished(Description description)80     public void testFinished(Description description) throws Exception {
81         System.out.println("testFinished");
82         tests++;
83     }
84 
85     @Override
testIgnored(Description description)86     public void testIgnored(Description description) throws Exception {
87         testStarted(description);
88         System.out.println("testIgnored");
89         ignored++;
90         Ignore ignore = description.getAnnotation(Ignore.class);
91         testFinished(description);
92     }
93 
94     @Override
testRunFinished(Result result)95     public void testRunFinished(Result result) throws Exception {
96         System.out.println("testRunFinished");
97         finishSuite();
98     }
99 
100     @Override
testRunStarted(Description description)101     public void testRunStarted(Description description) throws Exception {
102         System.out.println("testRunStarted");
103     }
104 
startSuite(Description description)105     private void startSuite(Description description) {
106         testClassName = description.getClassName();
107         suiteStart = System.currentTimeMillis();
108         failures = 0;
109         errors = 0;
110         tests = 0;
111         ignored = 0;
112 
113         file = new File(reportDir, testClassName + ".csv");
114     }
115 
finishSuite()116     private void finishSuite() {
117         if (testClassName == null)
118             return;
119 
120 
121         Set<Entry<Object, Object>> entries = System.getProperties().entrySet();
122         for (Entry<Object, Object> e : entries) {
123 //          Element prop = doc.createElement("property");
124 //          prop.setAttribute("name", "" + e.getKey());
125 //          prop.setAttribute("value", "" + e.getValue());
126 //          props.appendChild(prop);
127         }
128 
129         store();
130     }
131 
store()132     private void store() {
133 
134     }
135 
136 }
137