Skip to content

Dummy data

RedG's dummy data feature allows you to focus on the test data you really need. No more specifying dozens of (transitive) dependencies you do not need for your test but your database needs them to satisfy the foreign key constraints.

With RedG you can simply say "I want a dummy entity of that type" and you get one. With all of its dependencies set to other dummy objects. This works out-of-the-box with zero configuration in 99% of the cases.

The RedG main class generated by RedG contains a dummyXX method for each entity type.

Example

Let's see this in action in a small example. Consider the following database schema:

The example schema

Because the user needs a bank account (it is a NOT NULL foreign key), you have to specify a bank account if you want to create a user with the redG.addDemoUser(GDemoBankAccount bankAcc) method. Simply passing null will not work here.

If you now want to add a user and perform some tests that only require its first and last name, you can simply use a dummy as the bank account.

redG.addDemoUser(redG.dummyBankAccount())
    .firstName("Trevor")
    .lastName("Testcase");

As you can see, RedG does all the heavy work for you. No need to specify anything for the dummy. You get a valid dummy that satisfies every database constraint so you can test the first and last name without worrying about the excess baggage.

Customization

If you need to customize how RedG generates dummy data, see here.