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 :
- I instantiate a test database.
- I manually insert a message into it
- Then, I call the retrieveMessage to attempt to retrieve the message
- 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