junit:如何用自动填充的随机值模拟pojo类

3pmvbmvn  于 2021-07-03  发布在  Java
关注(0)|答案(1)|浏览(484)

有没有简单的方法来创建pojo类并在junit中填充随机值以便于测试?
例子:

Student student = new Student();
student.setName(name);
student.setAddress(address);
student.setAge(age)
--- 
---
studentService.save(student);

基本上,我希望能够轻松地创建pojo类,而不用花时间填充随机值。目的是用数据测试服务层或控制器层。

6jjcrrmo

6jjcrrmo1#

这里有一个podam的解决方案
梯度依赖

testImplementation 'uk.co.jemos.podam:podam:7.2.5.RELEASE'

例子

PodamFactory podamFactory = new PodamFactoryImpl();
Student student = podamFactory.manufacturePojo(Student.class);

相关问题