从零开始搭建测试框架,测试平台

一、功能描述

灵活支持多业务数据源;
测试用例集中式管理,结构化数据;
数据驱动做到脚本与测试数据解耦;
丰富的日志管理功能,支持异常监控,便于开发调试;
支持性能监控,比如业务数据源的慢SQL;
开发的便利性,能节省重复工作,降低开发成本;
灵活的扩展性,满足自定义的数据类型;
主流的技术栈,能跟上互联网技术节奏,不易于快速被淘汰;
友好的代码结构及注释,便于阅读及二次开发。

二、技术架构

三、主要特点

使用目前的主流 SpringBoot 2.2.0 作为项目的主体框架;
使用 Maven 作为构建项目,方便管理依赖的 JAR 包;
使用 MySQL 集中式管理测试用例,结构化数据;
使用 TestNG 作为测试框架,强大的参数化功能,方便执行测试脚本;
MySQL 数据库管理测试用例,SQL 参数化驱动用例运行,实现测试脚本和数据的解耦;
基于 Mybatis Generator 或者 Mybatis Generator GUI 自动化生成持久层代码,节省大量重复开发工作;
使用 TypeHandler 解决自定义类型预处理;
实现注解式动态数据源,满足 N 个业务数据源测试需求;
丰富的日志管理功能,支持异常调试,慢SQL监控;
友好的代码结构及注释,便于阅读及二次开发。

四、工具简介

准备工作:idea 2020.3

1. 开发框架SpringBoot,

日志框架Logback,日志收集ELK Graylog

2. 效率插件lombok

更多注解说明,可查看:https://projectlombok.org/features/index.html

3. 测试框架Testng,流式断言库AssertJ

关于AssertJ的说明,可查看:https://assertj.github.io/doc/
AssertJ 支持如下模块:
Core:AssertJ core is a Java library that provides a fluent interface for writing assertions.
Guava:AssertJ assertions for Guava provides assertions for Guava types like Multimap, Table, Optional, Range or ByteSource.
Joda-Time:AssertJ assertions for Joda-Time provides assertions for Joda-Time types like DateTime and LocalDateTime.
DB:AssertJ-DB provides assertions to test data in a database.
Neo4j:Provides assertions for Neo4j 3 or higher.
Swing:AssertJ Swing is a Java library that provides a fluent interface for functional Swing UI testing.

4. 测试报告ExtentReport,服务端测试报告Klov ExtentReports

4. 工具类库 Hutool,JSON 解析库 fastjson,Mock Server moco

五、项目结构
├─logs
│ └─spring-boot-logback # 日志文件
│ all_api-test-logback.log # 所有日志
│ err_api-test-logback.log # 错误日志
├─src
│ ├─main
│ │ ├─java
│ │ │ └─com
│ │ │ └─zuozewei
│ │ │ └─springbootdatadrivendemo
│ │ │ │ SpringbootDataDrivenDemoApplication.java # 启动类
│ │ │ │
│ │ │ ├─db
│ │ │ │ ├─auto # 存放MyBatis Generator生成器生成的数据层代码,可以随时删除再生成
│ │ │ │ │ ├─mapper # DAO 接口
│ │ │ │ │ └─model # Entity 实体
│ │ │ │ └─manual # 存放自定义的数据层代码,包括对MyBatis Generator自动生成代码的扩展
│ │ │ │ ├─mapper # DAO 接口
│ │ │ │ └─model # Entity 实体
│ │ │ ├─handler # 数据转换
│ │ │ └─service # 业务逻辑
│ │ │ └─impl # 实现类
│ │ │
│ │ └─resources
│ │ │ application.yml # 全局配置文件
│ │ │ generatorConfig.xml # Mybatis Generator 配置文件
│ │ │ logback-spring.xml # logback 配置文件
│ │ │ spy.properties # P6Spy 配置文件
│ │ │
│ │ ├─db
│ │ ├─mapper
│ │ │ └─com
│ │ │ └─zuozewei
│ │ │ └─springbootdatadrivendemo
│ │ │ └─db
│ │ │ ├─auto # 存放MyBatis Generator生成器生成的数据层代码,可以随时删除再生成
│ │ │ │ └─mapper # 数据库 Mapping 文件
│ │ │ │
│ │ │ └─manual # 存放自定义的数据层代码,包括对MyBatis Generator自动生成代码的扩展
│ │ │ └─mapper # 数据库 Mapping 文件
│ │ └─testng
│ │ │ APICollection-TestSuite.xml # 所用测试用例集
│ │ └─jdbcbapi
│ │ jdbcAPI-TestSuite.xml # 某API测试用例集
│ │
│ └─test
│ └─java
│ └─com
│ └─zuozewei
│ └─springbootdatadrivendemo
│ └─demo # 接口测试用例

posted @ 2021-11-19 10:51  雨 燕  阅读(476)  评论(0编辑  收藏  举报