For TestNG, what is the proper method of prefilling a data source containing a complex model when it will be queried using Hibernate?

I want to write tests for our internal Seam Framework-based website search engine that uses Hibernate + Lucene (for DB2) indexes for queries. What is the best solution to populate the data source before starting the TestNG package, when the project data model is quite complex, given the relationship of entities and field restrictions? For some test cases, at least a dozen database tables would require rows related to each other to adhere to the limitations of the data model. Ideally, Hypersonic will be used as in-memory use will reduce the execution time of our build process.

I hope my question is clear, since it is difficult to formulate a complete picture of my problem without throwing a massive wall of descriptive text and proprietary code. In principle, creating each object programmatically (creating instances of all objects using the Hibernate Home object, setting each property, saving the data source and making the transaction in FacesRequest @Test) is too cumbersome, given the data model and populate.sql script we already wrote (and are executed on DB2 to run a local website hosted on JBoss locally) cannot be used on Hypersonic! And every TestNG example that I come across on the Internet or in books contains roughly simple data sets that do not indicate a clear approach to my problem.

+3
source share
2 answers

In principle, creating each object programmatically (...) is too cumbersome, given the data model and populate.sql script that we have already written (and run in DB2 to locally host a website hosted on JBoss locally) to use on hypersonic!

If you want to reuse the SQL script, you can try H2 with DB2 compatibility mode, as suggested by @Arthur . If this does not work, try JavaDB / Derby, which is compatible with DB2, and you can also use in-memory.

script , , . DbUnit . DBUnitSeamTest Seam, DBUnit TestNG.

DbUnit, , databene benerator , DbUnit ( eclipse).

+2

, , ,

Person person = PersonBuilder.validPerson()
                             .withAddress(AddressBuider.validAddress())
                             .build();

h2 db2.

, . , ORM . , , . , , , , . , ORM. , , .

, Hypersonic, H2

  • IBM DB2, Apache Derby, HSQLDB, MS SQL Server, MySQL, Oracle PostgreSQL.

, , . .

, , . XUnit Fixture.

, ,

+3

Source: https://habr.com/ru/post/1769249/


All Articles