开发者

Tests with constraint checking errors not caught when using AbstractTransactionalSpringContextTests (rollback)

开发者 https://www.devze.com 2023-03-12 13:33 出处:网络
The majority of开发者_如何学C my integration tests use spring\'s AbstractTransactionalSpringContextTests to do a rollback instead of commiting to the database.This works well normally but because fore

The majority of开发者_如何学C my integration tests use spring's AbstractTransactionalSpringContextTests to do a rollback instead of commiting to the database. This works well normally but because foreign key constraints are not applied until the commit stage there's a hole in my testing strategy.

How can I improve my tests?

I want to avoid commiting if possible as this causes tests to take much longer to run (when there are many)


I understand you don't want to commit to the database e.g. flush the session, but performance might be acceptable when using an in-memory sqlite database for this purpose.

I've done unit tests using NHibernate (with Fluent NHibernate) and an in-memory sql-lite database (how to here); this works quite fast as long as you only create the relevant parts of your database instead of the complete schema.

You can easily extend the AbstractTransactionalSpringContextTests class to flush to the db, see the spring.net docs 22.2.10 or this thread on the spring.net forum, so you should be able to get this working quickly for your test suite.

0

精彩评论

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

关注公众号