在日常测试过程中,测试数据的准备占用了测试人员很大的精力。如果您处于学习阶段可以使用:https://test.igood.wang作者提供的数据中心,进行学习。如果您当前处于生产环境,建议您搭建私有数据中心。
数据中心使用
1:数据模板的声明
package wang.igood.example.data;
import wang.igood.test.base.data.APIData;
import java.io.Serializable;
@APIData(code = "DySearchcKey",name = "抖音关键字",description = "用于抖音搜索")
public class DySearchcKey implements Serializable {
@APIData(title = "关键字")
private String searcchKey;
public String getSearcchKey() {
return searcchKey;
}
public void setSearcchKey(String searcchKey) {
this.searcchKey = searcchKey;
}
@Override
public String toString() {
return "DySearchcKey{" +
"searcchKey='" + searcchKey + '\'' +
'}';
}
}
APIData是数据模板声明时使用的注解,变量注解中title对应着excel表中的表头
2:数据模板的注册
import wang.igood.example.data.DySearchcKey;
import wang.igood.test.base.Bootstrap;
import wang.igood.test.base.data.APIDataCenter;
import java.io.InputStream;
public class Application extends Bootstrap{
//系统初始化app
@Override
public void init() {
InputStream io = ClassLoader.getSystemResourceAsStream("app.properties");
initConfig(io);
}
//注册数据模板
@Override
public void register() {
APIDataCenter.getShareInstance().register(DySearchcKey.class);
APIDataCenter.getShareInstance().upload();
}
}
测试用例运行前会触发数据注册,只需要您在register中添加注册代码
APIDataCenter.getShareInstance().register(DySearchcKey.class);
3:测试数据准备
Excel表的方式存储,表头对应着数据模板中的title
4:测试数据的导入
5:测试数据的获取
DySearchcKey key = (DySearchcKey) APIDataCenter.getShareInstance().getData(DySearchcKey.class);
6:Demo下载地址:https://igood.oss-cn-beijing.aliyuncs.com/DYExample.zip
数据中心的搭建
压缩包中包含两部分 TestWeb-1.3-SNAPSHOT.war(WEB项目文件),db_auto_test.sql(数据库初始化文件)
第一步:创建Mysql数据库,并通过db_auto_test.sql初始化数据库
第二步:在Tomcat中部署JavaWeb项目,修改/WEB-INF/classes/application.properties 文件
url=jdbc:mysql://数据库地址:数据库端口/数据库名?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&autoReconnectForPools=true&useSSL=false
driverClassName=com.mysql.jdbc.Driver
username=数据库用户名
password=数据库密码
第三步:启动项目
http://项目地址:端口
显示该图片是就部署成功了。
微信号:CompanyAiHelper