给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格式,今天研究了下,分享给大家~ 首先需要引用服务,点击项目右键,添加引 ...
随机推荐
- 用CMakeLists.txt组织工程
1 一个工程会有多个CMakeLists.txt,如何组织这些CMakeLists.txt来构建一个工程? 1.1 最外层一个CMakeLists.txt,是总的CMakeList.txt,在这个里 ...
- Python爬虫-- PyQuery库
PyQuery库 PyQuery库也是一个非常强大又灵活的网页解析库,PyQuery 是 Python 仿照 jQuery 的严格实现.语法与 jQuery 几乎完全相同,所以不用再去费心去记一些奇怪 ...
- 我的Java开发学习之旅------>Java经典排序算法之插入排序
一.算法原理 插入排序法:所谓插入排序法乃是将一个数目插入该占据的位置. 假设我们输入的是 "53,27,36,15,69, 42" 我们从第二个数字开始,这个数字是27,我们的 ...
- Java拓展教程:文件DES加解密
Java拓展教程:文件加解密 Java中的加密解密技术 加密技术根据一般可以分为对称加密技术和非对称加密技术.对称加密技术属于传统的加密技术,它的加密和解密的密钥是相同的,它的优点是:运算速度快,加密 ...
- maven采用tomcat7启动项目
1.maven 集成tomcat7启动项目 <plugin> <groupId>org.apache.tomcat.maven</groupId> <arti ...
- SpringBoot2.0之整合ActiveMQ(点对点模式)
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...
- javascript正则(带g符号) 多次调用test 结果交替出现
链接:https://segmentfault.com/q/1010000000582051 http://stackoverflow.com/questions/2851308/why-does-m ...
- zabbix haproxy 监控
摘自: http://www.tuicool.com/articles/JrYNNrm 写的非常好,步步紧逼,环环相扣.直到成功! 文章首发站点:OpensGalaxy 这是一个HAProxy的zab ...
- CSS3实现3D木块旋转动画
CSS3实现3D木块旋转动画,css3特效,旋转动画,3D,立体效果,CSS3实现3D木块旋转动画是一款迷人的HTML5+CSS3实现的3D旋转动画. 代码下载:http://www.huiyi8.c ...
- html5--2.10综合实例2-移动端页面练习
html5--2.10综合实例2-移动端页面练习 学习要点 通过一个简单的移动手机页面,复习学过的内容 手机网页的测试 手机布局的屏幕设定 手机网页的测试方法 直接在手机上测试,比较麻烦,效果好 电脑 ...