Dependency between Business and DAL - Problems with unit testing

We just started to reorganize our code and are separating the DAL from the Business. We have also started playing with unit testing, but we've come up with a few problems.

1) Unit testing the DAL. Yes, we've noticed that this is not a trivial task, and are looking at using the com+ / service enterprise approch. The quuestion is: Are there any help for adding rollback option built into the Team Systems

2) Unit testing the Business. Quite a few of our business class depends quite heavily on the data access layer. The problem occurs when we create an instance of a business class, it requires a lot of DAL access. Typically today this access is built into the constructor, and it calls a lot of DAL components to get all entities required. We're unsure how to handle this. We have come up with three options:

  • Adding #ifdefs in the code, wich allows for switching between mock objects and the DAL object
  • Adding interfaces to the DAL objects (currently we dont have it. Should we always use interfaces on the DAL I don't see why except for unit testing) Adding interface would add possibility for a factory creation of the DAL objects, and thus allow for creating mock objects instead.
  • Doing integration test instead. That is testing the business objects together with the DAL objects directly connected with the test database.

We're currently in a steep learning process both in unit testing and following the best practice, so please correct me if I've misunderstood anything.

Thanks for any guidance.

Larsi



Answer this question

Dependency between Business and DAL - Problems with unit testing