View Javadoc

1   /*
2       Jameleon - An automation testing tool..
3       Copyright (C) 2007 Christian W. Hargraves (engrean@hotmail.com)
4   
5       This library is free software; you can redistribute it and/or
6       modify it under the terms of the GNU Lesser General Public
7       License as published by the Free Software Foundation; either
8       version 2.1 of the License, or (at your option) any later version.
9   
10      This library is distributed in the hope that it will be useful,
11      but WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13      Lesser General Public License for more details.
14  
15      You should have received a copy of the GNU Lesser General Public
16      License along with this library; if not, write to the Free Software
17      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */
19  package net.sf.jameleon.reporting;
20  
21  import net.sf.jameleon.TestCaseTag;
22  import net.sf.jameleon.exception.JameleonException;
23  import net.sf.jameleon.result.JameleonTestResult;
24  import net.sf.jameleon.result.TestCaseResult;
25  import net.sf.jameleon.util.JameleonUtility;
26  
27  import java.io.IOException;
28  import java.util.Calendar;
29  import java.util.Iterator;
30  import java.util.List;
31  
32  /***
33   * Reports the test run results is a simple form, suitable for STD OUT or a simple text file
34   */
35  public class SimpleTestRunReporter extends AbstractTestRunReporter{
36  
37      public void reportScriptResult(TestCaseTag tct, TestCaseCounter counter) {
38          try{
39              String scriptName = JameleonUtility.getFileNameFromScriptPath(tct.getFileName());
40              getWriter().write("\n"+ scriptName );
41              TestCaseResult tcr = tct.getResults();
42              if (tcr.failed()){
43                  List failedResults = tcr.getFailedResults();
44                  JameleonTestResult jtr;
45                  for (Iterator it = failedResults.iterator(); it.hasNext();){
46                      jtr = (JameleonTestResult)it.next();
47                      getWriter().write("\nFunctionId: " + jtr.getIdentifier());
48                      getWriter().write("\nLine #: " + jtr.getLineNumber());
49                      getWriter().write("\nRow #: " + jtr.getFailedRowNum());
50                      getWriter().write("\nError Message: " + jtr.getErrorMsg()+"\n");
51                  }
52                  getWriter().write(scriptName);
53              }
54              getWriter().write(" : " +tct.getResults().getOutcome());
55              getWriter().flush();
56          }catch(IOException ioe){
57              throw new JameleonException("Could not report simple results: "+ioe.getMessage());
58          }
59      }
60  
61      public void reportTestRunComplete(Calendar startTime, Calendar endTime, TestCaseCounter counter) {
62          try{
63              getWriter().write("______________________________________________________\n\n");
64              getWriter().write("Test Run: " + ReporterUtils.formatTime(startTime));
65              getWriter().write("\nTests run: " + counter.getNumRun());
66              getWriter().write(" Failed: " + counter.getNumFailed());
67              getWriter().write(" Time: " + ReporterUtils.getExecutionTime(startTime, endTime));
68              getWriter().write("\n______________________________________________________\n");
69              getWriter().flush();
70          }catch(IOException ioe){
71              throw new JameleonException("Could not report summary results: "+ioe.getMessage());
72          }
73      }
74  
75      public void reportTestRunStart(Calendar startTime) {
76          
77      }
78  
79  }