Let's assume I have StartCommandHandler
which has responsibility to create some file with required files. But for doing this I have to give him a set of sub-responsibilities, like:
- Checks whether file exists in the FTP
- If Not downloads files from multiple sources to the temp folder
- Then executes some script in the folder
- Then read generated file after script execution
- Then create zip from that folder
- Then remove that folder
- Then updates database
As a result of that Command Handler, we are creating folder with all required files. And now that folder is ready for another operations.
I have just read "Art of the Unit testing"
. And started to add unit tests. I have followed SOLID
principles as well. Especially, SRP
and DIP
, which are in my opinion prerequisites for Unit Testing.
So, most of that things which I stated above are done with specific interfaces. So, 90% job of that Command Handler is to call methods of dependencies. And 10% is the logic like this:
if(!_dependency1.IsAnySomething())
{
_dependency2.Download();
var isScriptNeeded = _dependency2.IsScriptNeeded();
if(isScriptNeeded)
{
var res = _dependency3.ExecuteScript();
_dependency4.SetScriptResult(res.Info, res.Date, res.State);
}
_dependency3.Archive();
_dependency5.DeleteTemp();
}
I already tested all dependencies of that command handler. But, hat command handler also includes some small logics like, is download file needed, or temp files are deleted or not and so on...
I have so many question in my mind like:
- May be Unit Testing doesn't make sense for such units? Integration Test to the rescue? Because, it seems wrong to test whether to check all calls, like whether
DeleteTemp
is called after download, or script is executed or not, or script result is passed in a right way toSetScriptResult
method. Is it GOOD Unit Test? - Is there any way to refactor that class for making it testable?