views:

103

answers:

4

I have a project with a lot of classes that use Nhibernate. Now I want to use NUnit to test those classes. Are there specific things I need to consider?

A: 

You need to create the session in the begging of (or during) the test....

That's it I guess...

Everything else is the same...

Dani
A: 

I would consider using NDBUnit. It allows you to unit test a database while gauranteeing the state of your database is unaltered by external factors. You can use this along with NUnit to test the class.

sgmeyer
Is ndbunit an extention of nunit? Or is it a stand-alone testing facility? I was also thinking about the nhibernate configuration...
Bart Van Eyndhoven
It is not an extension to NUnit although they do play along nicely.
sgmeyer
+2  A: 

Are you unit testing class mappings i.e. does the data save okay or logic inside the classes?

Mapping Tests

I suggest that you use Sqlite and in-memory testing for the hibernate mappings - although this is not technically unit testing. I would create a session on each time you run a test so as you are using the nunit framework use the [SetUp] attribute on a method to tell nunit to run the create session code. Make sure the session is closed and disposed of at the end of the test.

http://support.fluentnhibernate.org/discussions/help/87-in-memory-sqlite-database-for-persistencespecification-testing

Unit testing

Unit testing would involve mocking out most of nhibernate so that you were testing the actually classes.

http://ayende.com/Blog/archive/2009/04/18/mocking-nhibernate.aspx

Aim Kai