JAVA简单生成测试数据工具

news/2024/5/18 15:00:13 标签: android, 安卓, 反射, java

前一段时间为了方便简单的写了一个JAVA生成测试数据的工具类。

使用场景如下:

有时候定义好了类但是会需要测试数据,这个时候我们可能会需要如下操作。

//伪代码
A a =new A();
a.setB1("xxx");
a.setB2("xxx");
a.setB3("xxx");

//列表
List<A> list=new ArrayList();
for(int i=0;i<10;i++){
    A a =new A();
    a.setB1("xxx");
    a.setB2("xxx");
    a.setB3("xxx");
    a.setBB(new B());//.....子对象
    list.add(a);
}

实现的工具 只需要做如下操作即可

//生成单个对象
A a=TestObjectBuildUtils.get(A.class);
//生成十条数据
List<A> list = TestObjectBuildUtils.getList(A.class,10);

如果有特殊的生成数据选项例如

数据生成会在{}数组中选择

public class TestData implements Serializable {
    @TestObject(value = {"张三", "李四", "王五"})
    private String userName;
    @TestObject(value = {"13511111111", "13500000000"})
    public String userTel;
    @TestObject(value = {"2021-09-28 18:44:12", "2021-09-30 18:44:12"})
    private String createTime;
    @TestObject(value = {"113.0846", "113.1846"})
    private String svrLongitude;
    @TestObject(value = {"28.204844", "28.212222"})
    private String svrLatitude;
    @TestListType(listType = TestChildData.class)
    private List<TestChildData> data;
    private TestData2 testData2;

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public String getUserTel() {
        return userTel;
    }

    public void setUserTel(String userTel) {
        this.userTel = userTel;
    }

    public String getCreateTime() {
        return createTime;
    }

    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }

    public String getSvrLongitude() {
        return svrLongitude;
    }

    public void setSvrLongitude(String svrLongitude) {
        this.svrLongitude = svrLongitude;
    }

    public String getSvrLatitude() {
        return svrLatitude;
    }

    public void setSvrLatitude(String svrLatitude) {
        this.svrLatitude = svrLatitude;
    }

    public List<TestChildData> getData() {
        return data;
    }

    public void setData(List<TestChildData> data) {
        this.data = data;
    }

    public TestData2 getTestData2() {
        return testData2;
    }

    public void setTestData2(TestData2 testData2) {
        this.testData2 = testData2;
    }
}

gitee链接icon-default.png?t=LA92https://gitee.com/sarp/BuildTestData

github链接icon-default.png?t=LA92https://github.com/arpsyalin/BuildTestData


http://www.niftyadmin.cn/n/893188.html

相关文章

TF:tf.train.optimizer

tf的7中优化方法 optimizer tf.train.AdadeltaOptimizer(rate) optimizer tf.train.AdagradOptimizer(rate) optimizer tf.train.AdamOptimizer(rate) optimizer tf.train.FtrlOptimizer(rate) optimizer tf.train.GradientDescentOptimizer(rate) optimizer tf.train.M…

build.gradle引入第三方文件

在gradle中引入libs下的jar文件一般会这样&#xff0c;很是方便&#xff1a; implementation fileTree(dir: libs, include: [*.jar]) 引入aar一般会这么写,如果aar比较多&#xff0c;就需要得写很多如下类似代码&#xff0c;删除或添加都得改&#xff1a; implementation fi…

Java打包和重新打包

Mac打包JAR 生成class文件 javac -cp 依赖库A全路径:依赖库B全路径 -encoding utf-8 JAVA类文件 CD到Java的根路径/或者重新建完整路径 CD到根路径 打包jar jar -cvf 打包名.jar 根路径 运行 java -jar jar文件 参数 问题 1.找不到清单文件则无法运行。 解压后修改主…

IDEA 创建Spring项目Spring-5.2.3.RELEASE下载失败

找到maven的setting.xml 修改源即可。 一般没改成外部引用maven mac就在应用程序-显示包内容-/Applications/IntelliJ\ IDEA.app/Contents/plugins/maven/lib/maven3/conf/setting.xml

Android studio 常用快捷键记录

有时候总是突然忘记一些快捷键&#xff0c;尤其是用一下mac又用一下windows的时候&#xff0c;然后就总去搜索一下特此记录一下方便自己找&#xff1a; 功能MACWindows// 注释代码command/Ctrl//**/注释代码commandoption/CtrlAlt/格式化代码commandoptionLCtrlAltL去无效引用…

一个RecycerView Grid分区域时添加背景圆角

有时候设计师会设计如上图的设计。 我手里有个旧项目的代码&#xff0c;开发人员实现这个类型的布局用了一个scrollview嵌套了4个TextView 4个GirdView方式去弄....看了代码一言难尽.... 看不下去抽空写了一个例子&#xff0c;采用一个RecycerView去实现类似这个效果。下面…

记录一个APP跳转系统相机拍摄小问题

记录原因&#xff1a;在实现一个跳转拍视频的功能时候&#xff0c;因为写了如下代码&#xff0c;录制了后返回&#xff0c;结果发现私有目录cacheDir的文件一直为0k&#xff0c;仔细一想...这肯定是0k没得跑&#xff0c;因此记录一下这个乌龙。 val uri: Uri Uri.fromFile(fi…

TF:tf.dynamic_partition

用法 #encodingutf-8 import tensorflow as tfx tf.constant([11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22], shape [6,2]) #x的第0,2,4行作为y的第0行&#xff1b;x的第1,3,5行作为y的第3行 v tf.constant([0, 3, 0, 3, 0, 3]) #由于y至少有4行&#xff0c;所以第三个…