关于项目自动化测试架构的改良计划 - 读取原始xml文件

简介:

按照我们的架构,第一步是读取原始的xml文件到一个xml字符串中:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
  *
  *@author cwang58
  *@created date: Jun 10, 2013
  */
public  class  XMLReader {
                                     
     private  static  final  String LINE_SEPARATOR=System.getProperty( "line.separator" );
     private  static  String userDir = System.getProperty( "user.dir" );
     private  static  final  String fileSeparator=System.getProperty( "file.separator" );
     private  static  final  String dataFileName= "test_suite.xml" ;
                                     
     /**
      * build the data file path which depends on the platform
      * @param projectName
      * @return
      */
     public  static  String buildDataFilePath (String projectName){
         return  userDir+fileSeparator+ "src"
                       +fileSeparator+ "test"
                       +fileSeparator+ "resources"
                       +fileSeparator+projectName
                       +fileSeparator+ "data"
                       +fileSeparator+dataFileName;
                                                       
     }
                                     
     /**
      * read the file content then store contant into a string
      * @param source the file source name
      * @return
      * @throws IOException
      */
     public  static  String readContentFromFile(String source)  throws  IOException{
         File file =  new  File(source);
         // open a file reader to read the file content
         FileInputStream fis =  null ;
         InputStreamReader isr =  null ;
         BufferedReader reader =  null ;
         try  {
                                         
             fis =  new  FileInputStream(file);
             isr =  new  InputStreamReader(fis,  "utf-8" );
             reader =  new  BufferedReader(isr);
             StringBuffer bufferedFileContent =  new  StringBuffer();
             String line =  null ;
             while  ((line = reader.readLine()) !=  null ) {
                 bufferedFileContent.append(line).append(LINE_SEPARATOR);
             }
             return  bufferedFileContent.toString();
         catch  (FileNotFoundException ex) {
             ex.printStackTrace();
             return  null ;
         finally  {
             if (reader!= null )
                 reader.close();
             if (isr!= null )
                 isr.close();
             if (fis!= null )
                 fis.close();
         }
     }



代码很简单,就是一个基于文件流的操作,不再自己讲解。这个步骤对于架构图的第一步。





本文转自 charles_wang888 51CTO博客,原文链接:http://blog.51cto.com/supercharles888/1221718,如需转载请自行联系原作者
目录
相关文章
|
15天前
|
XML 前端开发 Java
讲解SSM的xml文件
本文详细介绍了SSM框架中的xml配置文件,包括springMVC.xml和applicationContext.xml,涉及组件扫描、数据源配置、事务管理、MyBatis集成以及Spring MVC的视图解析器配置。
36 1
|
8天前
|
运维
【运维基础知识】用dos批处理批量替换文件中的某个字符串(本地单元测试通过,部分功能有待优化,欢迎指正)
该脚本用于将C盘test目录下所有以t开头的txt文件中的字符串“123”批量替换为“abc”。通过创建批处理文件并运行,可实现自动化文本替换,适合初学者学习批处理脚本的基础操作与逻辑控制。
103 56
|
12天前
|
存储 消息中间件 运维
架构升级的救星!流量回放自动化测试的必备指南
大家好,我是小米,一名29岁的技术宅。今天分享一个物联网领域的实用技能——流量回放自动化测试。系统重构后,测试工作量巨大,本文介绍如何通过日志收集和数据回放进行自动化测试,包括离线、实时和并行回放模式,帮助快速定位Bug,提升测试效率和系统稳定性。欢迎关注我的微信公众号“软件求生”,获取更多技术干货!
21 3
|
16天前
|
XML JavaScript Java
java与XML文件的读写
java与XML文件的读写
16 3
|
17天前
|
安全 Linux 网络安全
Kali 渗透测试:利用HTA文件进行渗透攻击
Kali 渗透测试:利用HTA文件进行渗透攻击
35 1
|
28天前
|
Java C++
代码文件间重复性测试
本文介绍了如何使用代码相似性检测工具simian来找出代码文件中的重复行,并通过示例指令展示了如何将检测结果输出到指定的文本文件中。
|
17天前
|
安全 Linux 网络安全
Kali渗透测试:自动播放文件攻击
Kali渗透测试:自动播放文件攻击
31 0
|
17天前
|
XML 存储 缓存
C#使用XML文件的详解及示例
C#使用XML文件的详解及示例
44 0
|
18天前
|
XML 存储 Web App开发
查看 XML 文件
查看 XML 文件
|
12天前
|
缓存 监控 API
探索微服务架构中的API网关模式
【10月更文挑战第5天】随着微服务架构的兴起,企业纷纷采用这一模式构建复杂应用。在这种架构下,应用被拆分成若干小型、独立的服务,每个服务围绕特定业务功能构建并通过HTTP协议协作。随着服务数量增加,统一管理这些服务间的交互变得至关重要。API网关作为微服务架构的关键组件,承担起路由请求、聚合数据、处理认证与授权等功能。本文通过一个在线零售平台的具体案例,探讨API网关的优势及其实现细节,展示其在简化客户端集成、提升安全性和性能方面的关键作用。
45 2