How to fill all the fields in the class?

前端 未结 5 1646
时光说笑
时光说笑 2021-01-12 16:40

Suppose I have a class that has a lot of different fields. This class is a DTO and for testing purposes, I do not care about actual values, just it exists. Is there any tool

5条回答
  •  北恋
    北恋 (楼主)
    2021-01-12 17:19

    Just a small googling provide this results:

    • EasyRandom simple to use modern java solution, formerly known as Random beans
    • EasyRandom for Java 6, formerly known as JPopulator.
    • PODAM with a tutorial

    else you can use reflection to populate:

    • primitive/wrapper with default value
    • string with rendom value
    • Collection(set,list) with random size and re-using code to populate

    and so on.

    Else XML binding (with jaxb or other technology) can be an option but needs to prepare xml with data in advance.
    Except frameworks all other solutions have two big issues: needs to be written and a lot of testing!

提交回复
热议问题