美文网首页
Appium 测试报告--测试集报告

Appium 测试报告--测试集报告

作者: 长新 | 来源:发表于2017-08-06 18:05 被阅读573次

测试集中报告可以看成是一个总表,这时可以用Excel 的图表工具自动生成图表,整个测试集测试通过后再统计各个级别的报告

图表模板如下

public static void statistical() throws IOException{

String TestReport=System.getProperty("user.dir")+"\\测试报告\\测试报告.xlsx";

System.out.println("报告文件"+TestReport);

FileInputStream ReportFile = new FileInputStream(TestReport);

//创建工作本

XSSFWorkbook  ReportBook = new XSSFWorkbook(ReportFile);

//获取Sheet 名称

XSSFSheet TestStepSheet=ReportBook.getSheet("TestStep");

for (int i=1;i<=TestStepSheet.getLastRowNum();i++){

String txt=Excel.GetString(TestStepSheet, i,9 );

if (txt.equals("PASS")){

Constants.TestStepPass=Constants.TestStepPass+1;

}

else {

Constants.TestStepFail=Constants.TestStepFail+1;

}

}

XSSFSheet TestCaseSheet=ReportBook.getSheet("TestCase");

for (int i=1;i<=TestCaseSheet.getLastRowNum();i++){

String txt=Excel.GetString(TestCaseSheet, i,2 );

if (txt.equals("PASS")){

Constants.TestCasePass=Constants.TestCasePass+1;

}

else {

Constants.TestCaseFail=Constants.TestCaseFail+1;

}

System.out.println("TestCase Pass=="+Constants.TestCasePass+"TestCase Fail=="+Constants.TestCaseFail);

}

XSSFSheet TestSuiteSheet=ReportBook.getSheet("TestSuite");

for (int i=1;i<=TestSuiteSheet.getLastRowNum();i++){

String txt=Excel.GetString(TestSuiteSheet, i,1 );

if (txt.equals("PASS")){

Constants.TestSuitePass=Constants.TestSuitePass+1;

}

else {

Constants.TestSuiteFail=Constants.TestSuiteFail+1;

}

}

double TestStepRate=(double)Constants.TestStepPass/(Constants.TestStepPass+Constants.TestStepFail);

double TestCaseRate=(double)Constants.TestCasePass/(Constants.TestCasePass+Constants.TestCaseFail);

double TestSuiteRate=(double)Constants.TestSuitePass/(Constants.TestSuitePass+Constants.TestSuiteFail);

System.out.println("测试步骤通过率="+TestStepRate+"测试用例通过率=="+TestCaseRate+"测试套件通过率=="+TestSuiteRate);

XSSFSheet Test_Index_Sheet=ReportBook.getSheet("首页---数据统计");

//写入统计结果

if (Test_Index_Sheet!=null) {

XSSFRow Row=Test_Index_Sheet.getRow(2);

//数值型格式

XSSFCellStyle numStyle = ReportBook.createCellStyle();

numStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("0"));

//双精度型格式

XSSFCellStyle doubleStyle = ReportBook.createCellStyle();

doubleStyle.setDataFormat(HSSFDataFormat.getBuiltinFormat("0.00%"));

//写入测试套件的结果

XSSFCell  cell0=Row.createCell(0);

cell0.setCellValue(Constants.TestSuitePass);

cell0.setCellStyle(numStyle);

XSSFCell  cell1=Row.createCell(1);

cell1.setCellValue(Constants.TestSuiteFail);

cell1.setCellStyle(numStyle);

//写入测试套件的通过率

XSSFCell  cell2=Row.createCell(2);

cell2.setCellValue(TestSuiteRate);

cell2.setCellStyle(doubleStyle);

//写入测试用例的结果

XSSFCell  cell3=Row.createCell(3);

cell3.setCellValue(Constants.TestCasePass);

cell3.setCellStyle(numStyle);

XSSFCell  cell4=Row.createCell(4);

cell4.setCellValue(Constants.TestCaseFail);

cell4.setCellStyle(numStyle);

//写入测试用例的通过率

XSSFCell  cell5=Row.createCell(5);

cell5.setCellValue(TestCaseRate);

cell5.setCellStyle(doubleStyle);

//写入测试步骤的结果

XSSFCell  cell6=Row.createCell(6);

cell6.setCellValue(Constants.TestStepPass);

cell6.setCellStyle(numStyle);

XSSFCell  cell7=Row.createCell(7);

cell7.setCellValue(Constants.TestStepFail);

cell7.setCellStyle(numStyle);

//写入测试步骤的通过率

XSSFCell  cell8=Row.createCell(8);

cell8.setCellValue(TestStepRate);

cell8.setCellStyle(doubleStyle);

//将执行时间写入到对应单元格中

// Row.createCell(9).setCellValue(Constants.min);

//创建文件输出流

FileOutputStream fileOut = new FileOutputStream(TestReport);

// 写入文件输出流到Excel

ReportBook.write(fileOut);

//关闭文件流

fileOut.close();

//释放Excel

ReportFile.close();

}

else {

System.out.println("首页统计的Sheet 不存在");

}

}

上面那个模板因为有Excel 中的图表,不能删除,如果每次运行后怎么将历史数据清空呢,我们可以将清空数据放在脚本启动时也可以放在统计报告之前

清空操作逻辑是先将前一次的测试报告全数复制一份成以当前时间格式命名的文件

复制之后再清空除首页--统计报表之外的所有Sheet 报表

代码如下

//清除旧记录

public static void CleanData() throws IOException {

String TestReport=System.getProperty("user.dir")+"\\测试报告\\测试报告.xlsx";

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss");

//生成时间戳

String  dateString = formatter.format(new Date());

File SourceFile=new File(TestReport);

File Destination=new File(System.getProperty("user.dir")+"\\测试报告\\"+dateString+".xlsx");

FileUtils.copyFile(SourceFile, Destination);

FileInputStream ReportFile = new FileInputStream(TestReport);

//创建工作本

try {

XSSFWorkbook  ReportBook = new XSSFWorkbook(ReportFile);

//移除Sheet

if (ReportBook.getSheet("TestStep")!=null) {

ReportBook.removeSheetAt(ReportBook.getSheetIndex("TestStep"));

}

if (ReportBook.getSheet("TestCase")!=null) {

ReportBook.removeSheetAt(ReportBook.getSheetIndex("TestCase"));

}

if (ReportBook.getSheet("TestSuite")!=null) {

ReportBook.removeSheetAt(ReportBook.getSheetIndex("TestSuite"));

}

//创建文件输出流

FileOutputStream fileOut = new FileOutputStream(TestReport);

// 写入文件输出流到Excel

ReportBook.write(fileOut);

//关闭文件流

fileOut.close();

} catch (Exception e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

//释放Excel

ReportFile.close();

}

相关文章

  • Appium 测试报告--测试集报告

    测试集中报告可以看成是一个总表,这时可以用Excel 的图表工具自动生成图表,整个测试集测试通过后再统计各个级别的...

  • 输入测试报告的步骤

    python+appium使用HTMLTestRunner输出自动化测试报告:参考:https://www.jia...

  • 接口测试--discover读取所有测试用例

    运行测试用例脚本: 生成测试报告 测试脚本修改: 生成测试报告: 测试报告效果图:

  • 外卖接口压力测试报告

    外卖接口性能测试报告 ​ ​ 1 概述 1.1 目的 本测试报告为外卖接口的性能测试报告,目的在于总结测试阶段的测...

  • 测试报告发送到Jenkins服务器

    步骤一:搭建nginx 步骤二:运行测试测试用例,生成测试报告 运行自己的代码,生成测试报告 并把移动测试报告到n...

  • 软件测试管理快速入门9测试报告

    什么是测试报告? 测试报告包含: 测试活动和最终测试结果的摘要 评估测试的执行情况 根据测试报告,利益相关者可以 ...

  • Appium-Mac-Android教程2-测试报告

    简介 在教程1已经完成Appium安装,接下来我们完成App录制脚本,并生成测试报告 1.录制脚本 2.生成报告 ...

  • 如何写测试报告

    关键:测试报告的目的是什么?谁会关注你的测试报告、关注的点是什么,需要有侧重测试人员、测试时间1、测试报告对象介绍...

  • 测试报告

    一、定义 记录测试的过程和结果,对发现的问题和缺陷进行分析的文档 二、测试报告分类 阶段测试报告 整体测试报告 三...

  • 测试报告

    1.测试报告 定义:记录测试的过程和结果,对发现的问题和缺陷进行分析的文档 2.测试报告分类 阶段测试报告 整体测...

网友评论

      本文标题:Appium 测试报告--测试集报告

      本文链接:https://www.haomeiwen.com/subject/hhknlxtx.html