java 造数据_java测试造数据神器JavaFaker

背景

构造测试数据时,需要绞尽脑汁浪费时间,JavaFaker可以释放你的生产力

githup地址

安装

com.github.javafaker

javafaker

0.17.2

使用

随机生成一百个学生及考生分数

学生模型

/*** 测试model 学生

*@authorszhu*/

public class Student implements Comparable{/*** 姓名*/

privateString name;/*** 分数*/

private doublescore;public Student(String name, doublescore) {this.name =name;this.score =score;

}publicString getName() {returnname;

}public voidsetName(String name) {this.name =name;

}public doublegetScore() {returnscore;

}public void setScore(doublescore) {this.score =score;

}

@Overridepublic intcompareTo(Student o) {return Double.compare(this.score, o.score);

}

@OverridepublicString toString() {return "Student{" +

"name='" + name + '\'' +

", score=" + score +

'}';

}

}

2、指定汉语

Faker FAKER = newFaker(Locale.CHINA);

中文姓名

FAKER.name().fullName();1~100之间两位小数数字

FAKER.number().randomDouble(2, 1, 100)

具体如下:

importcom.github.javafaker.Faker;importjava.util.List;importjava.util.Locale;importjava.util.stream.Collectors;importjava.util.stream.Stream;/*** 模型生成工厂

*

*@authorszhu*/

public classModelFactory {/*** faker 指定汉语,默认英语*/

private static Faker FAKER = newFaker(Locale.CHINA);/*** 随机生成一定数量学生

*

*@paramnumber 数量

*@return学生*/

public static List listStudentList(final intnumber) {return Stream.generate(() -> new Student(FAKER.name().fullName(), FAKER.number().randomDouble(2, 1, number))).limit(number).collect(Collectors.toList());

}/*** main函数*/

public static void main(String[] args) throwsException {

listStudentList(100).forEach(System.out::println);

}

}

运行效果如下

Student{name='余立轩', score=73.13}

Student{name='吴嘉熙', score=56.27}

Student{name='孙瑞霖', score=66.46}

Student{name='张志强', score=90.39}

Student{name='卢烨磊', score=29.98}

Student{name='于健雄', score=77.65}

Student{name='钱伟祺', score=72.74}

Student{name='郑思', score=26.2}

Student{name='张弘文', score=36.61}

Student{name='尹伟泽', score=55.85}

Student{name='高明辉', score=62.03}

Student{name='谢文', score=36.15}

Student{name='吴浩', score=65.94}

Student{name='赵文', score=1.88}

Student{name='苏鹏飞', score=17.84}

Student{name='钱峻熙', score=8.81}

Student{name='邹烨伟', score=30.07}

Student{name='吴明哲', score=46.42}

Student{name='邓伟宸', score=54.28}

Student{name='唐健雄', score=70.23}

Student{name='董思淼', score=43.5}

Student{name='贾昊强', score=20.77}

Student{name='郭鹏', score=26.25}

Student{name='金晋鹏', score=25.16}

Student{name='武绍辉', score=20.46}

Student{name='秦立轩', score=83.37}

Student{name='任文昊', score=55.13}

Student{name='徐哲瀚', score=20.26}

Student{name='郭昊然', score=58.53}

Student{name='叶峻熙', score=26.48}

Student{name='李天磊', score=30.1}

Student{name='苏荣轩', score=32.88}

Student{name='朱鑫鹏', score=56.78}

Student{name='莫越彬', score=18.77}

Student{name='毛烨华', score=11.39}

Student{name='龙驰', score=9.28}

Student{name='金昊天', score=7.99}

Student{name='叶博涛', score=28.7}

Student{name='孟文轩', score=81.7}

Student{name='高智渊', score=62.83}

Student{name='邵思远', score=51.35}

Student{name='黄鹏涛', score=32.37}

Student{name='何瑞霖', score=77.09}

Student{name='侯煜城', score=34.92}

Student{name='赖明杰', score=38.4}

Student{name='方明', score=79.8}

Student{name='毛黎昕', score=66.07}

Student{name='武志泽', score=50.99}

Student{name='赵修洁', score=13.2}

Student{name='苏擎苍', score=9.22}

Student{name='韩晓博', score=37.48}

Student{name='萧烨伟', score=15.73}

Student{name='江立果', score=23.78}

Student{name='严苑博', score=75.86}

Student{name='魏果', score=1.28}

Student{name='董昊然', score=72.64}

Student{name='唐越彬', score=14.42}

Student{name='陈修洁', score=68.48}

Student{name='吕君浩', score=4.67}

Student{name='姚锦程', score=13.18}

Student{name='钱思', score=88.58}

Student{name='萧鸿煊', score=2.99}

Student{name='方鹤轩', score=87.83}

Student{name='张峻熙', score=27.47}

Student{name='宋鹏煊', score=27.45}

Student{name='魏伟泽', score=73.5}

Student{name='徐熠彤', score=18.0}

Student{name='侯雪松', score=29.99}

Student{name='罗明辉', score=62.75}

Student{name='谭烨伟', score=65.24}

Student{name='汪君浩', score=83.27}

Student{name='段立辉', score=14.18}

Student{name='秦鸿煊', score=12.54}

Student{name='邵振家', score=45.83}

Student{name='孔立果', score=48.19}

Student{name='蒋哲瀚', score=23.36}

Student{name='龚熠彤', score=22.79}

Student{name='苏思源', score=29.13}

Student{name='秦浩轩', score=71.87}

Student{name='孔琪', score=65.91}

Student{name='顾彬', score=73.58}

Student{name='陈子涵', score=17.82}

Student{name='沈鹏飞', score=33.55}

Student{name='孟伟祺', score=13.03}

Student{name='钱立诚', score=38.05}

Student{name='黄博超', score=68.61}

Student{name='郝瑾瑜', score=18.91}

Student{name='林金鑫', score=64.76}

Student{name='夏笑愚', score=49.82}

Student{name='邱睿渊', score=2.62}

Student{name='孔伟诚', score=39.17}

Student{name='叶浩然', score=85.48}

Student{name='袁晟睿', score=89.67}

Student{name='龙瑞霖', score=10.89}

Student{name='贾弘文', score=22.21}

Student{name='方俊驰', score=63.3}

Student{name='刘鹏飞', score=30.46}

Student{name='苏烨华', score=40.82}

Student{name='杨浩宇', score=12.27}

Student{name='金立辉', score=80.11}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/310093.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Largest Rectangle in a Histogram (动态规划+奇思妙想单调栈)求最大矩状图面积

感觉动态规划都是玄妙的很,思维题吧(单调栈思维) 题解:让求最大矩形面积,宽为1,暴力超时 可以发现 当第i-1个比第i个高的时候 比第i-1个高的所有也一定比第i个高 于是可以用到动态规划的思想 令l…

ASP.NET Core分布式项目实战(详解oauth2授权码流程)--学习笔记

最近公司产品上线,通宵加班了一个月,一直没有更新,今天开始恢复,每日一更,冲冲冲任务13:详解oauth2授权码流程我们即将开发的产品有一个用户 API,一个项目服务 API,每个服务都需要认…

java 先进先出的map_「 深入浅出 」java集合Collection和Map

本系列文章主要对java集合的框架进行一个深入浅出的介绍,使大家对java集合有个深入的理解。 本篇文章主要具体介绍了Collection接口,Map接口以及Collection接口的三个子接口Set,List,Queue。什么是集合Java集合类存放于 java.util…

二叉搜索树(模板)

题意:先给一组数据构建一颗二叉搜索树作为标准树。紧跟着n组数据中,判断每组 数据构成的二叉搜索树是否和标准树yi一样。 思路:两棵树如果一样的话,就是拥有一样的节点,在每个节点上具有相同的值,且 在相同遍历条件下&…

C++类模板中的static成员

从类模板实例化的每一个模板类有自己的类模板数据成员&#xff0c;该模板的所有对象共享一个static数据成员。 代码如下: #include <iostream> using namespace std;template<typename T> class Person { public:static int a;};template<typename T> int …

C#并发编程之初识并行编程

写在前面之前微信公众号里有一位叫sara的朋友建议我写一下Parallel的相关内容&#xff0c;因为手中商城的重构工作量较大&#xff0c;一时之间无法抽出时间。近日&#xff0c;这套系统已有阶段性成果&#xff0c;所以准备写一下Parallel的相关内容&#xff0c;正好也延续之前的…

java 下拉列表 枚举_「Java三分钟」精准而优雅——枚举类详解

关注我&#xff0c;每天三分钟&#xff0c;带你轻松掌握一个Java相关知识点。1.为什么要用枚举你在读一个老工程代码时&#xff0c;是否经常看见有几个类&#xff0c;里面放着成百上千的静态常量&#xff0c;场面相当恐怖&#xff0c;而且如果不加注释&#xff0c;很多你都不知…

Not so Mobile(二叉树递归输入同时建树){天平}

题意&#xff1a; 给出一个大天平&#xff0c;大天平中还有许多小天平&#xff0c;求出所有的天平是否平衡&#xff1b;平衡条件为wldl wrdr&#xff1b; 题目 Before being an ubiquous communications gadget, a mobile was just a structure made of strings and wires …

C++类型转换基本语法

static_cast 用于内置的数据类型 还有具有继承关系的指针或者引用 代码如下: #include <iostream> using namespace std;class Building {}; class Animal{}; class Cat:public Animal{};int main() {int a 97;char c static_cast<char>(a);cout << c &l…

java arraylist 源代码_java中ArrayList的源代码是什么

展开全部package java.util;public class ArrayList extends AbstractListimplements List, RandomAccess, Cloneable, java.io.Serializable{private static final long serialVersionUID 8683452581122892189L;/*** The array buffer into which the elements of the ArrayL…

在阿里云函数计算上部署.NET Core 3.1

使用阿里云ECS或者其他常见的VPS服务部署应用的时候&#xff0c;需要手动配置环境&#xff0c;并且监测ECS的行为&#xff0c;做补丁之类的&#xff0c;搞得有点复杂。好在很多云厂商&#xff08;阿里云、Azure等&#xff09;提供了Serverless服务&#xff0c;借助于Serverless…

[PAT乙级]1023 组个最小数

给定数字 0-9 各若干个。你可以以任意顺序排列这些数字&#xff0c;但必须全部使用。目标是使得最后得到的数尽可能小&#xff08;注意 0 不能做首位&#xff09;。例如&#xff1a;给定两个 0&#xff0c;两个 1&#xff0c;三个 5&#xff0c;一个 8&#xff0c;我们得到的最…

C++中函数调用时的三种参数传递方式(x,*x,x)

先看三种方式实现函数中参数传递的实例程序 输入描述&#xff1a;两个待交换的整数程序输出&#xff1a;交换后得按值传递两个整数&#xff08;一&#xff09;按值传递&#xff1a;按值传递的过程为&#xff1a;首先计算出实参表达式的值&#xff0c;接着给对应的形参变量分配…

java 持续交付_【Java架构:持续交付】一篇文章搞掂:Jenkins

1.1、使用yum安装JDKa、检查系统是否有安装open-jdkrpm -qa |grep javarpm -qa |grep jdkrpm -qa |grep gcj如果没有输入信息表示没有安装。如果安装可以使用rpm -qa | grep java | xargs rpm -e --nodeps 批量卸载所有带有Java的文件 这句命令的关键字是javab、检索yum中包含…

抱歉,请不要把 “业务逻辑层” 理解为 “业务中台”

这是头哥侃码的第197篇原创在IAS2019中台架构峰会上&#xff0c;我曾与一位年轻帅气的技术小伙来了一番有趣的对话。因为和朋友有约&#xff0c;所以我在现场互动结束之后&#xff0c;就急匆匆地跟其他嘉宾打了声招呼&#xff0c;抱着笔记本冲出了会场。但没想到刚到电梯口&…

C++异常处理分析

C异常处理基本语法: 代码如下: #include <iostream> using namespace std;int divide(int x, int y) {if (y 0) throw y;return x / y; }void test01() {//试着去捕获异常try{divide(10, 0);}/*catch (int){cout << "除数为0!" << endl;} */catc…

java文件损坏_java – 损坏的文件处理

我想知道如果任何人有任何建议处理损坏的文件与Apache POI我试图打开一个文件&#xff0c;并收到此消息&#xff1a;Exception in thread "main" org.apache.poi.hssf.record.RecordInputStream$LeftoverDataException: Initialisation of record 0x1C left 2 bytes …

Harmonic Number (II) LightOJ - 1245(找规律?大数f(n)=n/1+n/2+n/3+......+n/n)

题意&#xff1a;让我们求f&#xff08;n&#xff09;n/1n/2n/3......n/n&#xff1b;同时注意n/i取整&#xff1b; 思路&#xff1a;首先我们先看数据的范围&#xff0c;n (1 ≤ n < 2 31)&#xff0c;数据范围太大&#xff0c;如果我们按 照题目中的代码直接暴力肯定超时…

陌陌的 Service Mesh 探索与实践

Service Mesh Virtual Meetup 是 ServiceMesher 社区和 CNCF 联合主办的线上系列直播。本期为 Service Mesh Virtual Meetup#1 &#xff0c;邀请了四位来自不同公司的嘉宾&#xff0c;从不同角度展开了 Service Mesh 的应用实践分享&#xff0c;分享涵盖来自陌陌和百度的 Servi…

C标准输入流

标准输入流对象cin&#xff0c;重点掌握的函数: cin.get()//一次只能读取一个字符 cin.get(一次参数)//读一个字符 cin.get(两个字符)//可以读字符串 cin.getline() cin.ignore() cin.peek() cin.putback() 标准输入流cin.get() 代码如下: #include <iostream> using n…