views:

601

answers:

3

I'm using Spring.net with NHiberante (HibernateTemplate) to implement my DAO's.

I also have some integration tests, that extend from 'AbstractTransactionalDbProviderSpringContextTests '.

DI is working fine, and all test pass BUT sometimes they pass even when they shouldn't.

For example if my hbm.xml files have an error like this:

<class name="Confluence.Domain.User" table="THIS TABLE DOES NOT EXIST">

The tests fails, but if the error is like this one:

<many-to-many class="Confluence.Domain.User" column="THIS COLUMN DOES NOT EXIST"/>

the tests pass silently hiding the bug.

I'm testing it using SetComplete() and checking the DB for the changes, but I think the whole idea of this kind of tests is not to do so.

Can anyone tell me how to fix this issue?

Thank you very much!

@Ben: If I have to actually execute the SQL scripts to see if they work, what is the benefit of using this kind of Spring tests?

+1  A: 

If you have a syntax error in your mapping, then NHibernate will fail on config.BuildSessionFactory()

But for mispelled/non-existence database objects, the only way for NHibernate to know is to actually run a query... So you might employ some integration tests to test insert/select on a single entity, to make sure it works.

Not sure what this has to do with Spring.NET though.

Ben Scheirman
A: 

hi. I'm using Spring.net with NHiberante (HibernateTemplate) to implement my DAO's. then,using HibernateTemplate to execute method ,it's null. why? find all document on internet. no document,no everybody introduce the questation.

+2  A: 

Hi,

When testing your NH based DAO's you should flush the session so that the database is updated with the new information but still rollback as before. How to do this is explained here - http://forum.springframework.net/showthread.php?t=5246 I've added this to the reference docs. Hope this helps.

Cheers, Mark