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?
You need to create the session in the begging of (or during) the test....
That's it I guess...
Everything else is the same...
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.
You can mock NHibernate. The links below might help you:
http://stackoverflow.com/questions/1828878/mocking-an-nhibernate-isession-with-moq http://stackoverflow.com/questions/448405/nhibernate-testing-mocking-isession
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.
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