给Fitnesse添加json格式报告
需求: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格式报告的更多相关文章
- JS学习笔记(3)--json格式数据的添加,删除及排序方法
这篇文章主要介绍了json格式数据的添加,删除及排序方法,结合实例形式分析了针对一维数组与二维数组的json格式数据进行增加.删除与排序的实现技巧,需要的朋友可以参考下 本文实例讲述了json格式 ...
- WebApi返回Json格式字符串
WebApi返回json格式字符串, 在网上能找到好几种方法, 其中有三种普遍的方法, 但是感觉都不怎么好. 先贴一下, 网上给的常用方法吧. 方法一:(改配置法) 找到Global.asax文件,在 ...
- JSON格式序列化与反序列化(List、XML)
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.I ...
- (Spring4 json入门)Spring4+SpringMVC+页面数据发送与接收(json格式)
jar包(Maven仓库): Spring4 jar包(Maven仓库): 在测试过程中我查看了网上的一些教程,但是那些教程都是在Spring3环境下的,Spring3和Spring4解析json需要 ...
- MVC学习系列6--使用Ajax加载分部视图和Json格式的数据
Ajax的应用在平时的工作中,很是常见,这篇文章,完全是为了,巩固复习. 我们先看看不使用json格式返回分部视图: 先说需求吧: 我有两个实体,一个是出版商[Publisher],一个是书[Book ...
- 【转】如何把Json格式字符写进text文件中
http://www.cnblogs.com/insus/p/4306640.html http://json2csharp.chahuo.com/ 本篇一步一步学习怎样把显示于网页的json格式的字 ...
- webapi返回json格式优化
一.设置webapi返回json格式 在App_Start下的WebApiConfig的注册函数Register中添加下面这代码 config.Formatters.Remove(config.For ...
- Json格式转换
验证Json格式可以进入 http://json.cn/ json简单说就是javascript中的对象和数组,所以这两种结构就是对象和数组两种结构,通过这两种结构可以表示各种复杂的结构1.对象:对象 ...
- ajax访问服务器返回json格式
使用ajax访问服务器返回多条数据,比如返回一个表中的所有数据,页面该如何处理呢?如何获取数据呢?一直不会用ajax返回json格式,今天研究了下,分享给大家~ 首先需要引用服务,点击项目右键,添加引 ...
随机推荐
- cmake使用第三方库
1 link_directories和target_link_libraries 1.1 link_directories 告诉linker去这些目录去找library. 1.2 target_lin ...
- python使用记录
#2017-7-17 1.用len()函数可以获得list元素的个数; len()可以获取字符串长度 2. list正向0开始索引,,逆向-1开始索引; 也可以把元素插入到指定的位置,比如索引号为1的 ...
- "静态方法里仅仅能调用静态变量和静态方法"具体解释
静态方法里能够调用静态方法和静态变量,同一时候也能调用非静态方法和非静态变量. public class Test { public Test() {}; public Test(int i) {th ...
- FI 常用表
FI 常用表 GL部分:FAGLFLEXT(FMGLFLEXT) 总账汇总表 GLT0 旧总帐汇总表 SKA1 总账科目主记录 (科目表) ...
- [2017-11-21]Abp系列——T4应用:权限树定义
本系列目录:Abp介绍和经验分享-目录 今天介绍下,如何使用T4根据json文件自动生成权限定义. 先看成果 成果是: 要新增一个权限定义时,打开Json文件,找到目标节点,加个权限定义: 生成下Co ...
- okhttp 特点 module版本冲突 集成module到项目
特点适合大小文件上传.下载,但对图片不会执行缓存是一个缺点 集成module到项目 右上角添加 lib和module版本冲突问题,删除lib下的即可
- 一次跨域请求出现 OPTIONS 请求的问题及解决方法
问题背景浏览器从一个域名的网页去请求另一个域名的资源时,域名.端口.协议任一不同,都是跨域 在前后端开发过程经常会遇到跨域问题.网上也都有解决方案. 写这篇文章时,我们碰到的一个场景是:要给s系统做一 ...
- winform中通过事件实现窗体传值思路【待修改】
Form2向Form1传值 private Form1 form1;//定义一个类型为Form1类型的字段,用于存储传递过来的Form对象 public void Se ...
- 时尚创意VI矢量设计模板
时尚创意VI矢量设计模板 创意VI VI设计 企业VI 时尚背景 信封设计 封面设计 杯子 桌旗 帽子 EPS矢量素材下载 http://www.huiyi8.com/vi/
- MySQL_杭州11月1-29号在线产品在线天数、销售天数_20161129
杭州11月1-29号在线产品在线天数.销售天数 1.产品在这个时间段内的每一天的在线情况,然后聚合计算每个产品的在线天数,每一天的在线情况 如果在线记为1,不在线为null 2.计算每个产品在这个时间 ...