How to add dummy data to your java object

H

When you are unit testing, it is sometimes necessary to supplement an object with dummy data. Unfortunately, to fill a large object manually, it crawls a lot of time and work. Fortunately, there is a tool that saves us the time and work!

At https://code.google.com/p/dummycreator/wiki/DummyCreator, you can find a java library that fills an object with dummy data by typing one line of code.

If you use Maven, you can add the following dependency:

<dependency>
    <groupId>de.dev-eth0.dummycreator</groupId>
    <artifactId>dummy-creator</artifactId>
    <version>1.2</version>
    <scope>test</scope>
</dependency>

Example

In this example, we want to add dummy data for an object User.

public class User {

    private Long id;
    private String firstName;
    private String lastName;
    private String email;

    //getters & setters...
}

Now, to fill this object, type the following code:

User user = new DummyCreator().create(User.class);

It’s easy as that! Enjoy! 😀

1 comment

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Tag Cloud

Categories