I usually do Fakes by inheriting from the real service class and swapping out a couple of methods or even a whole dependency (say an http handler), so my test will go through every little bit of "normal" code except for the last part that actually does the thing (writing on disk/db or making an http call to an external service).
One of the ways to achieve partial service mocking is to use Multiple inheritance to mock "danger" part of class. Python example is here (CleaningBot testing cases, Raymond Hettinger - Super considered super! - PyCon 2015): https://www.youtube.com/watch?v=EiOglTERPEo
If I am testing the CloudUploader I only want to make sure that the CloudService is used as I understood from the CloudService API definition. Therefore I would use a mockCloudService. Then I would have an integration test suite against the CloudService to make sure that the Service actually works as expected in a SIT environment. Fakes like mocks or stubs are completely safe for me if I am clear about what is the intention of the test case. What risk I need to cover in each test. I do not see the point to avoid using certain tools or techniques, every tool has a reason to be. :-) I hope it helps to spark some good ideas.
I usually do Fakes by inheriting from the real service class and swapping out a couple of methods or even a whole dependency (say an http handler), so my test will go through every little bit of "normal" code except for the last part that actually does the thing (writing on disk/db or making an http call to an external service).
ReplyDeleteOne of the ways to achieve partial service mocking is to use Multiple inheritance to mock "danger" part of class. Python example is here (CleaningBot testing cases, Raymond Hettinger - Super considered super! - PyCon 2015): https://www.youtube.com/watch?v=EiOglTERPEo
ReplyDeleteIf I am testing the CloudUploader I only want to make sure that the CloudService is used as I understood from the CloudService API definition. Therefore I would use a mockCloudService. Then I would have an integration test suite against the CloudService to make sure that the Service actually works as expected in a SIT environment. Fakes like mocks or stubs are completely safe for me if I am clear about what is the intention of the test case. What risk I need to cover in each test. I do not see the point to avoid using certain tools or techniques, every tool has a reason to be. :-) I hope it helps to spark some good ideas.
ReplyDelete