mardi 18 août 2015

TDD approach when using a data access layer and an application layer

I'm new to TDD. I want some tips on how to unit tests an application formed by a data layer that implements actual database access statements, and an application layer whose job is limited to calling the data layer methods. For example :

In my data layer class, called CassandraDataLayer, I have a retrieveMessage method :

class CassandraDataLayer:

    def retrieveMessage(self,message_id):
        #database access statements to retrieve the message
        #returns a Message class instance

On the other hand, in my application layer class, called ApplicationLayer, I have the following retrieveMessage method :

class ApplicationLayer:

    def retrieveMessage(self,message_id):
        return self.dataLayer.retrieveMessage(message_id)

Do I have to do unit tests for both of the two methods ?

To test my CassandraDataLayer retrieveMessage method, I've proceeded as the following :

  1. I instantiate a test database.
  2. I manually insert a message into it
  3. Then, I call the retrieveMessage to attempt to retrieve the message
  4. Finally, assert that the inserted message and the retrieved one are equal.

But, then, how can I test the application layer class retrieveMessage method ? Do I have to use the same logic again ? Isn't it redudant ?

Aucun commentaire:

Enregistrer un commentaire