Why Random-JPA?

1 minute read

In today’s software world, testing is treated as important as the production code.

The products are moving towards the goal of continuous delivery. And the prerequisite for achieving this goal is to have a complete automation suite.

Testing Java code is fairly easy as a developer have many tools available to achieve it, such as junit, testng, mockito. But when it comes to testing SQL queries a developer faces a lot of problems, and spends a lot of time just to create data set in order to test the queries. In most of the scenarios it takes more time to write test than writing the production code.

To list some of the main challenges a developer has.

  • Know the relationship between tables.
  • Spends a lot of time creating test fixtures for each entity.
  • Management/Maintenance of relationship in complex data scenario.
  • Rewriting a lot of fixture if a new entity is introduced in the hierarchy.
  • A developer finds hard to create data if there is many joined tables.
  • Creating random object for unit testing.

Random-JPA was created as a lightweight utility to help developers create test data with minimum configuration. Random-JPA takes care of the relationship between tables and creates a hierarchy for all the parent entities. When using this utility a developer, will just have to specify the list of all the entities which he wants to create. Its random-JPA’s job to manage and create all the entities. It provides easy access to all the entities created and prints all the.

A typical project will consist of hundreds of entities, thousands of queries and tens of models, and your test should focus on all the data conditions, rather focusing on the conditions, developer spends all his efforts and time in just creating a data set, in this process, miss out to test critical data condition. You can utilize random-JPA to create random data for both unit & integration tests.

This approach makes sure that every time we are working with integration test we will have a complete, new set of data to work with, reducing the chances of data corruption.

Nothing wastes more time than to manage dependency of entities and create random data and persist it to database.

And so Random-JPA was born…

Categories:

Updated:

Leave a comment