1

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.

  • You can either unit test using an Oracle database (sort of a contradiction), or avoid the SQL that SQLite doesn't understand. There aren't going to be any other databases that understand the Oracle-specific code. Why don't you use integration tests to cover the Oracle-specific code? – Robert Harvey Dec 11 '13 at 21:54
  • Why would you not test against the dbms you are targetting? – GrandmasterB Dec 11 '13 at 22:10
  • This is an existing application and an existing framework – dineshsbisht Dec 11 '13 at 22:16
  • Why not change your outer joins to use the standard syntax? Of course there still may be Oracle-only features that you use. – kevin cline Dec 11 '13 at 23:10
2

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".

  • I like both choices. I wish I could do the first one.. but I am still learning unit tests and can't modify a lot of DAO code. I think the second is seems more doable at this point of time. Thank you! – dineshsbisht Dec 12 '13 at 14:53
0

I wouldn't consider needing a database as part of the test to be unit testing. That's more like integration testing. A unit test shouldn't need something external to the method being tested, especially a database. Your unit test should test that the correct sql is being generated, not that the database is doing the right thing.

  • Well so there is a scenario where the function is searching for records. I am unit testing the function. the search function internally executes the query against the database. In order for me to not get an exception, I would need something which can execute the query the search function is trying to execute. I am definitely not trying to test the database part. – dineshsbisht Dec 11 '13 at 22:21
  • Mockito or JMock will be your friend. They'll mock the everything you're not testing. My recommendation is Mockito, it's easier to work with I think. If you need more power to test, then add in PowerMock's PowerMockito lib. – Jim Barrows Dec 12 '13 at 16:16
  • The problem with testing "that the correct sql is being generated" is that "the correct sql" is often hard to determine. If it was easy, no one would have any questions about it. A unit test for code running against Oracle using mocks is simply a lie, I've seen dozens of them pass against completely invalid code, because the code was absolutely correct, generating syntactically correct sql statements, which didn't work against the database because a column name changed. – EKW Sep 28 '18 at 13:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.