给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格式,今天研究了下,分享给大家~ 首先需要引用服务,点击项目右键,添加引 ...
随机推荐
- viewport详解
本文主要讲解viewpor相关知识. 参考资料&内容来源 博客园:https://www.cnblogs.com/zaoa/p/8630393.html 博客园:http://www.cnbl ...
- Quartz Job scheduling 基础实现代码
Quartz 集成在 SpringBoot 中分为 config.task.utils.controller 和 MVC 的三层即 controller.service.dao 和 entity. c ...
- ajax进度条
.graph { width: 400px; height: 25px; border: 1px solid #f8b3d0; } .bar { background-color: #ffe7f4; ...
- g2o求解BA 第10章
1.g2o_bal_class.h1.1 projection.hg2o还是用图模型和边,顶点就是相机和路标,边就是观测,就是像素坐标.只不过这里的相机是由旋转(3个参数,轴角形式,就是theta*n ...
- ScrollView当显示超出当前页面时自动移动到最底端【转】
本文转载自:http://gundumw100.iteye.com/blog/1162964 卷轴视图(ScrollView)是指当拥有很多内容,一屏显示不完时,需要通过滚动来显示视图.比如在做一个阅 ...
- Linux_服务器_06_VMware虚拟机下安装CentOS7.0图文教程
二.参考资料 1.VMware虚拟机下安装CentOS7.0图文教程
- listen and translation exercise 51
You are supposed to be having fun now. I have to hand in my biology paper tomorrow. Listen, you litt ...
- C++ string的查找函数和npos特殊值
STL中的string有6个查找函数: 1.find() 2.rfind() 从最后一个字符开始往前找. 3.find_first_of() 4.find_not_first_of() 5.find_ ...
- Codeforces Round #397 题解
Problem A. Neverending competitions 题目大意 一个团队有多个比赛,每次去比赛都会先订机票去比赛地点,然后再订机票返回.给出\(n\)个含有起止地点的购票记录(不按时 ...
- setsockopt函数功能及参数详解
Socket描述符选项[SOL_SOCKET] #include <sys/socket.h> int setsockopt( int socket, int level, int opt ...