开发者

testing web-database apps with maven

I want to test my开发者_运维问答 orm-part of my web application written in java-jpa. When there is the test goal of maven running, the creating tables in database didn't trigger yet, because the app is not deployed on the server yet. Is there a way, how can I test this? When I say test, I mean for example do some persisting then some queriyng, check the results are OK, then continue. I think it's probably better than typing it by and hand everytime...


It is independent of Maven but DBUnit will provide all you need for database testing and will run as part of junit tests.

See:

http://www.dbunit.org/howto.html

Also useful for this are running the tests intransactions os the database is left in the same state after the test. Spring provides some nice ways of acheiving this. See here:

9.3.5.4 Transaction management - at http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/testing.html#testing-tx


You didn't specify the peristence provider you are using, so I'm not sure if my answer will be of any help. In case you are using Hibernate...

Hibernate3 Maven Plugin has a goal that generates a DDL script from your mappings (it supports JPA annotations, too). Then you can use Maven SQL plugin to execute the DDL script against your database.

This blog post has an example configuration for the Hibernate3 plugin: http://unmaintainable.wordpress.com/2008/04/12/hibernate3-schema-creation/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜