C# – Unit test DAO code using SQL Lite when the application database is Oracle

cnhibernateunit testing

We have an application with Oracle backend. The DAO layer is written in C# and uses nHibernet to perform the data operations.

To unit test our DAO code, we use SQL Lite which creates the database based on our existing mapping in the project.

Some of our nHibernate queries that go to oracle use (+) for outer joins. Now SQL Lite doesn't understand (+).

There can be some more syntax from Oracle that SQL Lite doesn't understand. How do we fix problems like these?

What are the other database systems that can be used for unit testing the application code.

Best Answer

Testing against a different DB than the one you're going to use in production isn't going to give you any benefits. What's the point? Some of your tests might pass against SQL Lite but fail when connected to oracle. Worse than useless.

So you've got two choices:

  1. Mock out your DAO layer, so that your code doesn't actually talk to a DB, and thus making them "real" unit tests. Now you are actually testing your c# code and not the DB nor nhibernate.

  2. Connect to another Oracle DB (eg, a UnitTesting DB with dummy data in it) and test against that, which would be my preferred choice. The TDD nazi's will scream at you "it's not a REAL UNIT TEST" to which I'll answer "I don't care what it's called, it's testing my code which is what I need".

Related Topic