Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What would you put into the unit test of a repository class (data access layer)?

I'd like to write a unit test for my data access layer to make sure that everything works allright in it. The question is, what kind of things should I put into the tests?

The DAL is a static Repository class which hides the underlying layer (Fluent NHibernate) and exposes stuff to the public through an IQueryable.

I thought about

  • CRUD (Create/Retrieve/Update/Delete) operations
  • Transactions

Is there anything else about a DAL that is worth testing?
Thanks in advance for your answers!

like image 892
Venemo Avatar asked Dec 10 '22 06:12

Venemo


2 Answers

Repository implementation is tested with integration tests, not unit tests. Isolating repository implementation (mocking ORM) is almost impossible. Please take a look at this answer. Integration test uses a real ORM combined with real or fake (usually in-memory) database to do following:

  • saving new object
  • change -> persist -> restore sequence
  • all 'Find' methods

Essentially you testing the correctness of:

  • mappings (even if you use fluent)
  • criteria
  • hql or sql queries

Transactions are usually handled by an application layer, not repositories. You might be interested in this answer. Encapsulating IQueryable in the repository implementation will make testing a lot easier for you.

like image 194
Dmitry Avatar answered Apr 27 '23 04:04

Dmitry


  1. Need to test proper Exception handling
  2. Time Out Parameter of Database Connection
  3. Time Out Parameter of Store Procedure invocation
  4. Proper input parameters mapping . If store procedure expects to receive float but receive int.
like image 45
Gregory Nozik Avatar answered Apr 27 '23 05:04

Gregory Nozik