Bart Van Eyndhoven
Bart Van Eyndhoven

Reputation: 84

C#: Use NUnit to test classes that use Nhibernate

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?

Upvotes: 0

Views: 1523

Answers (4)

Aim Kai
Aim Kai

Reputation: 2909

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

Upvotes: 2

henginy
henginy

Reputation: 2071

You can mock NHibernate. The links below might help you:

Mocking an NHibernate ISession with Moq NHibernate testing, mocking ISession

Upvotes: 2

sgmeyer
sgmeyer

Reputation: 645

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.

Upvotes: 0

Dani
Dani

Reputation: 15069

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

That's it I guess...

Everything else is the same...

Upvotes: 0

Related Questions