码迷,mamicode.com
首页 > 其他好文 > 详细

7.动态生成测试结果文件

时间:2020-05-25 21:03:38      阅读:82      评论:0      收藏:0      [点我收藏+]

标签:file   报告   close   jmeter   测试结果   hmm   sts   定义   pac   

将测试结果根据时间日期保存到本地文件,使用后置处理器

import java.text.SimpleDateFormat;

import java.util.Date;

import java.io.*;

SimpleDateFormat fileDate = new SimpleDateFormat("yyyyMMddHHmm");//以分钟精度命名文件

SimpleDateFormat filePathDate = new SimpleDateFormat("yyyyMMdd");//以天精度命名目录

if(vars.get("FailureMessage")!=null){

  String responseMsg = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date())+"----"+vars.get("FailureMessage");

  String filePath = "E:\\apache-jmeter-3.3\\data";//定义目录

  filePath = filePath + filePathDate.format(new Date());//拼接完整目录

  File file = new File(filePath );

  if (!file.exists()){ //判断是否已存在目录

        file.mkdirs();

   }

   String filesPath = filePath +" \\"+filePathDate.format(new Date())+"回归测试报告"+".txt";//拼接完整文件名称

   File file1  = new File(filesPath );

  if (!file1.existis()){//判断是否已存在文件

       file1.createNewFile();

   }

  BufferedWriter  writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file1,true)));

  writer.write(responseMsg );

  writer.flush();

  writer.newLine();

  writer.close();

}

 

7.动态生成测试结果文件

标签:file   报告   close   jmeter   测试结果   hmm   sts   定义   pac   

原文地址:https://www.cnblogs.com/yinzone/p/12960789.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!