ericlefevre

September 6, 2007

Unitils: a better Gienah?

Filed under: hibernate, java, spring, test — Eric Lefevre @ 11:59 am

On my current project, I am using Gienah as a way to integrate JUnit tests with Spring. I am rather pleased with the result, keeping my unit tests quite clean.

I just heard today about Unitils, a more ambitious tool. In addition to Spring, it supports TestNG, DbUnit, EasyMock, and Hibernate (ie. almost all that we are using here!). It also provides a number of additional services, such as helper asserts.

Especially intriguing are two things:

  • they recommend temporarily removing some db constraints, and provide help to do so (”To keep database tests maintainable, test data files have to be as small as possible. (Referential) constraints however don’t help you to achieve this. We advise to disable all foreign key and not null constraints. Doing so makes it possible to specify only the data that matters for your test.“)
  • they handle database versions is a way very similar to Ruby on Rails (”The database maintainer monitors a directory on the filesystem that contains DDL scripts for creating the structure of the database. The name of these scripts should comply with following naming convention: <version>_<some name>.sql. For example: 001_create_person_table.sql, 002_create_car_table.sql“)

See here for details.

February 22, 2007

Test Driven Design and Data Access Layer

Filed under: hibernate, java, tdd, test — Eric Lefevre @ 10:50 am

I am currently writing the Data Access Layer of a Java project using Hibernate and I want to apply TDD on my work. The part that is concerned with the database is the mapping of objects on the database schema, and the queries.
As a recap, there are the options:
(more…)

February 15, 2007

Hibernate: so, the identifier field *is* mandatory after all!

Filed under: hibernate, java — Eric Lefevre @ 12:40 pm

Is it obvious to everyone that an identifier is mandatory in Hibernate? I actually thought that Hibernate generated some kind of internal identifier for classes that do not specify one.

The documentation says:

saveOrUpdate() does the following: […] if the object has no identifier property, save() it

That strongly implies that you can have no identifier, right?

In the test that I have written recently, I wanted to keep things as simple as possible. Just a String column in a table.
(more…)

Powered by WordPress