需求:fitnesse自带xml、junit、html格式报告,现在需要添加json格式的报告,且报告中只展示执行错误的用例信息

修改文件:

fitnesse.http.Response.java

fitnesse.responders.run.SuiteResponder.java

添加文件:

fitnesse.reporting.history.JsonReFormatter.java

fitnesse.resources.templates.suiteJson.vm

fitnesse.http.Response.java:添加下面红色字体部分

 ...
public Response(String formatString) {
Format format; if ("html".equalsIgnoreCase(formatString)) {
format = Format.HTML;
} else if ("xml".equalsIgnoreCase(formatString)) {
format = Format.XML;
} else if ("junit".equalsIgnoreCase(formatString)) {
format = Format.JUNIT;
} else if ("text".equalsIgnoreCase(formatString)) {
format = Format.TEXT;
} else if ("json".equalsIgnoreCase(formatString)) {
14 format = Format.JSON;
15 }
else {
format = Format.HTML;
}
setContentType(format.getContentType());
} public Response(String format, int status) {
this(format);
this.status = status;
} public boolean isXmlFormat() {
return Format.XML.contentType.equals(contentType);
} public boolean isHtmlFormat() {
return Format.HTML.contentType.equals(contentType);
} public boolean isTextFormat() {
return Format.TEXT.contentType.equals(contentType);
} public boolean isJunitFormat() {
return Format.JUNIT.contentType.equals(contentType);
} public boolean isJsonFormat() {
43 return Format.JSON.contentType.equals(contentType);
44 }
...

fitnesse.responders.run.SuiteResponder.java:添加下面红色字体部分

 ...

  private void createMainFormatter() {
if (response.isXmlFormat()) {
mainFormatter = newXmlFormatter();
} else if (response.isTextFormat()) {
mainFormatter = newTextFormatter();
} else if (response.isJunitFormat()) {
mainFormatter = newJunitFormatter();
} else if(response.isJsonFormat()){
11 mainFormatter = newJsonFormatter();
12 }
else {
mainFormatter = newHtmlFormatter();
}
} .... protected BaseFormatter newTextFormatter() {
return new TestTextFormatter(response);
} protected BaseFormatter newJunitFormatter() {
return new JunitReFormatter(context, page, response.getWriter(), getSuiteHistoryFormatter());
} protected BaseFormatter newJsonFormatter() {
29 return new JsonReFormatter(context, page, response.getWriter(), getSuiteHistoryFormatter());
30 }

protected BaseFormatter newHtmlFormatter() {
return new SuiteHtmlFormatter(page, response.getWriter());
}
...

fitnesse.reporting.history.JsonReFormatter.java:添加该文件

 import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.io.Writer; import fitnesse.FitNesseContext;
import fitnesse.reporting.BaseFormatter;
import fitnesse.wiki.WikiPage; import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;
import org.xml.sax.SAXException; /**
*
* Format test results as Json report. This responder returns an alternate
* format of the test history.
*/
public class JsonReFormatter extends BaseFormatter implements Closeable { private final FitNesseContext context;
private final Writer writer;
private final SuiteHistoryFormatter historyFormatter; public JsonReFormatter(FitNesseContext context, WikiPage page, Writer writer, SuiteHistoryFormatter historyFormatter) {
super(page);
this.context = context;
this.writer = writer;
this.historyFormatter = historyFormatter;
} @Override
public void close() throws IOException {
historyFormatter.close(); // read file based on historyFormatter time-stamp
VelocityContext velocityContext = new VelocityContext();
velocityContext.put("formatter", this);
velocityContext.put("suiteExecutionReport", historyFormatter.getSuiteExecutionReport());
VelocityEngine velocityEngine = context.pageFactory.getVelocityEngine();
Template template = velocityEngine.getTemplate("suiteJson.vm");
template.merge(velocityContext, writer);
writer.close();
} @Override
public int getErrorCount() {
return historyFormatter.getErrorCount();
} TestExecutionReport makeTestExecutionReport(File file) throws IOException, SAXException, InvalidReportException {
return new TestExecutionReport(file);
} }

fitnesse.resources.templates.suiteJson.vm:添加该文件

 #set( $String = "" )
#macro( format $s )$String.format("%.3f", $s)#end
#set($suiteTotalRunTimeSeconds = $suiteExecutionReport.totalRunTimeInMillis / 1000.0 )
{"testsuite_name":"#escape($suiteExecutionReport.rootPath)","tests":"$suiteExecutionReport.pageHistoryReferences.size()","failures":"$suiteExecutionReport.finalCounts.wrong","disabled":"$suiteExecutionReport.finalCounts.ignores","errors":"$suiteExecutionReport.finalCounts.exceptions","time":"#format($suiteTotalRunTimeSeconds)","testcase":[
#set($failure_count = $suiteExecutionReport.finalCounts.wrong)
#set($error_count = $suiteExecutionReport.finalCounts.exceptions)
#set($all_count = $failure_count+$error_count)
#foreach ($reference in $suiteExecutionReport.pageHistoryReferences)
#set($classname = $formatter.getClassName($reference))
#set($runTimeSeconds = $reference.RunTimeInMillis / 1000.0 )
#if($reference.testSummary.exceptions > 0 || $reference.testSummary.wrong > 0 )
{"name":"#escape($reference.pageName)","assertions":"$reference.testSummary.right","time":"#format($runTimeSeconds)",
#set($all_count = $all_count - )
#if($suiteExecutionReport.finalCounts.wrong > 0)
"failure_message":"$reference.testSummary.wrong errors",
#end
#if($reference.testSummary.exceptions > 0)
"error_message":"$reference.testSummary.exceptions exceptions",
#end
"system_out":"$reference.pageName?pageHistory&resultDate=$reference.resultDate"}
#if($all_count > 0)
,
#end
#end
#end
]}

给Fitnesse添加json格式报告的更多相关文章

  1. JS学习笔记(3)--json格式数据的添加,删除及排序方法

    这篇文章主要介绍了json格式数据的添加,删除及排序方法,结合实例形式分析了针对一维数组与二维数组的json格式数据进行增加.删除与排序的实现技巧,需要的朋友可以参考下   本文实例讲述了json格式 ...

  2. WebApi返回Json格式字符串

    WebApi返回json格式字符串, 在网上能找到好几种方法, 其中有三种普遍的方法, 但是感觉都不怎么好. 先贴一下, 网上给的常用方法吧. 方法一:(改配置法) 找到Global.asax文件,在 ...

  3. JSON格式序列化与反序列化(List、XML)

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.I ...

  4. (Spring4 json入门)Spring4+SpringMVC+页面数据发送与接收(json格式)

    jar包(Maven仓库): Spring4 jar包(Maven仓库): 在测试过程中我查看了网上的一些教程,但是那些教程都是在Spring3环境下的,Spring3和Spring4解析json需要 ...

  5. MVC学习系列6--使用Ajax加载分部视图和Json格式的数据

    Ajax的应用在平时的工作中,很是常见,这篇文章,完全是为了,巩固复习. 我们先看看不使用json格式返回分部视图: 先说需求吧: 我有两个实体,一个是出版商[Publisher],一个是书[Book ...

  6. 【转】如何把Json格式字符写进text文件中

    http://www.cnblogs.com/insus/p/4306640.html http://json2csharp.chahuo.com/ 本篇一步一步学习怎样把显示于网页的json格式的字 ...

  7. webapi返回json格式优化

    一.设置webapi返回json格式 在App_Start下的WebApiConfig的注册函数Register中添加下面这代码 config.Formatters.Remove(config.For ...

  8. Json格式转换

    验证Json格式可以进入 http://json.cn/ json简单说就是javascript中的对象和数组,所以这两种结构就是对象和数组两种结构,通过这两种结构可以表示各种复杂的结构1.对象:对象 ...

  9. ajax访问服务器返回json格式

    使用ajax访问服务器返回多条数据,比如返回一个表中的所有数据,页面该如何处理呢?如何获取数据呢?一直不会用ajax返回json格式,今天研究了下,分享给大家~ 首先需要引用服务,点击项目右键,添加引 ...

随机推荐

  1. $CLASS('page__hd')[0].style.backgroundColor="red"

    const $ID = (p) => document.getElementById(p)const $CLASS = (p) => document.getElementsByClass ...

  2. exception_action

    for i in range(3, -2, -1): try: print(4 / i) except Exception as e: print(Exception) print(e)

  3. swift中反向循环

    First of all, protocol extensions change how reverse is used: for i in (1...5).reverse() { print(i) ...

  4. Machine Learning No.8: Clusting

    1. K-means algorithm 2. K-means optimization objective 3. Random initialization

  5. [egret+pomelo]实时对战游戏杂记(5)

    之前大体了解了pomelo服务端的运行的大体运行流程,下面详细的学习一下在服务端比较重要的一个容器模块bearcat,在bearcat的wiki中我们可以对其有个大概的了解,在服务端示例的代码中也大量 ...

  6. 【转载】帧缓冲驱动程序分析及其在BSP上的添加

    原文地址:(四)帧缓冲驱动程序分析及其在BSP上的添加 作者:gfvvz 一.BSP修改及其分析   1. BSP中直接配置的四个寄存器 S3C6410数据手册的第14.5部分是显示控制器的编程模型部 ...

  7. CSS那个背景图片的坐标怎么设置?怎么计算的?

    background:url(images/hh.gif) no-repeat -10px 0;},作用是移动背景的位置. 背影图片的左上角相对当前元素左上角的坐标. 右为X轴正半轴, 下为Y轴正半轴 ...

  8. Spring Boot2.0之 整合JDBC

    很入门的知识,大家了解下就OK maven配置文件pom: spring: datasource: url: jdbc:mysql://localhost:3306/test username: ro ...

  9. 部署nginx支持lua

    nginx yum -y install gcc pcre pcre-devel openssl openssl-devel  GeoIP GeoIP-devel lua lua-develwget ...

  10. DOM (文档对象模型(Document Object Model)

    DOM(文档对象模型(Document Object Model) 文档对象模型(Document Object Model,简称DOM),是W3C组织推荐的处理可扩展标志语言的标准编程接口.在网页上 ...