Unit Test a create/save scenario in Clean Architecture

176 views
Skip to first unread message

Breno Sarkis

unread,
Feb 17, 2014, 2:37:58 PM2/17/14
to clean-code...@googlegroups.com
Hello again!

I'm looking for some advices on how to handle these scenarios: 

- Create Scenario -

Suppose you have 2 interactors, one that creates a table and another that creates a table revision, the behavior I want to test is, when you create a table, a default table revision is created and given to it, so I want to assure that when I create table A, its revision is 0.0.1.

How would you test this? I thought of two different approaches:

1 - I'd create a spy for the table interactor and a spy for the revision, so I'd check that the table interactor created and sent a request to the revision with the right parameters. (then I dont know if I should test the execution of the revision interactor as a whole, or just that it received the right request, because I think that testing the revision interactor itself should be a different test).

2 - I'm still not really sure whether it would be ok to have my CreateTableInteractor return a table entity (instead of returning void), assuming that It would, I could check that the table.Revision is equal to a default revision.


- Save Scenario -

3- Speaking strictly about unit testing, how would you test a save method in a gateway? would you just ensure that it was called with the right parameters? 


What I'm trying to do is slowly add unit tests to a legacy code base, in which the relationship between the domain objects are really confusing and wide, this table example is the easiest part of the whole feature, considering this, is it common to have mutiple interactors collaborating?


Thanks!

daniphp

unread,
Feb 22, 2014, 1:55:28 AM2/22/14
to clean-code...@googlegroups.com
For creation I would suggest a single Interactor that uses 2 Repositories/Gateways.
In general you should not unit test concrete gateways. There is little value to that. You could create some integration tests if there is value in create/save actions.

James Green

unread,
Feb 22, 2014, 3:42:17 AM2/22/14
to clean-code...@googlegroups.com
Hi,

I understand where you are coming from - a difficult place.

Have you considered extracting the table management code out entirely, and instead adopting a third party technology such as liquibase? Not many groups can claim table creation is their primary source of income so it is a candidate for subcontracting to a third party.. 

Sent from my iPad
--
The only way to go fast is to go well.
---
You received this message because you are subscribed to the Google Groups "Clean Code Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clean-code-discu...@googlegroups.com.
To post to this group, send email to clean-code...@googlegroups.com.
Visit this group at http://groups.google.com/group/clean-code-discussion.

Breno Sarkis

unread,
Feb 27, 2014, 2:07:14 PM2/27/14
to clean-code...@googlegroups.com
Dani and James

Thanks for the responses, but I think you misunderstood my question, I'll try to express myself better:

I need to garantee that when I create A, I also create B with a default structure, my main question is, in this unit test, is B a mock or a stub?

About the save method, I'm not considering testing concrete gateways, to be honest I think I was too concerned about code coverage actually, I just wanted to make sure that my save method was tested, I don't know how though. (maybe I should take it as Roy Osherove says, if it doesn't have logic in it, you shouldnt test it). 
To unsubscribe from this group and stop receiving emails from it, send an email to clean-code-discussion+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages