Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Test data generator for JPA or Hibernate

Are there any tools or libraries that can be used to generate test data using JPA or entity beans? I believe this will be very helpful for unit testing where we can have an in memory database with data dynamically generated just when we start our testing. So, there will be no communication with actual DB servers and not any waste of time.

I was only able to find JPAMock. But it is still under development. It would be nice if someone could provide a good pointer.

Thanks a lot.

like image 766
Bala Avatar asked Oct 31 '11 09:10

Bala


People also ask

What is test data generator?

A test data generator is a specialized software tool that generates false or mock data for use in testing software applications. The generated data may be either random or specifically chosen to create a desired result.

What is sequence generator in Hibernate?

SEQUENCE Generation. To use a sequence-based id, Hibernate provides the SequenceStyleGenerator class. This generator uses sequences if our database supports them. It switches to table generation if they aren't supported.

What is @ID in Hibernate?

Annotation Type Id @Target(value={METHOD,FIELD}) @Retention(value=RUNTIME) public @interface Id. Specifies the primary key of an entity. The field or property to which the Id annotation is applied should be one of the following types: any Java primitive type; any primitive wrapper type; String ; java. util.


1 Answers

You could try out Random-JPA, a framework designed to generate random data. The setup is minimal.

I developed it and have been using it for over an year on our production tests. It works perfectly fine. Though it currently supports Oracle, MySQL & MSSQL with full feature.

Code: https://github.com/kuros/random-jpa

Tutorial: https://kuros.in/random-jpa

like image 54
Kumar Rohit Avatar answered Sep 28 '22 08:09

Kumar Rohit