Azure / azure-storage-cpp

Microsoft Azure Storage Client Library for C++
http://azure.github.io/azure-storage-cpp
Apache License 2.0
131 stars 147 forks source link

Mocking azure-storage-cpp objects for unit testing #386

Closed ajs97 closed 3 years ago

ajs97 commented 3 years ago

I am writing c++ code to talk to azure blob service. I create azure::storage::cloud_blob_container and azure::storage::cloud_block_blob objects, and I use many of the APIs defined for these objects (get_block_blob_reference, delete_blob, upload_text, etc). Since the functions/constructors are not virtualized, I am having trouble defining mock objects and mocking the calls (note that I am using the gtest/gmock framework to unit test).

A workaround that I found online was to templatize the code, and define mock_cloud_blob_container objects, etc and implement all the calls in the mock object. Though this is a bit painful, this is the only solution that I know of to deal with this case.

Is there some easier method to mock the SDK objects, or is the method I am following the only way?

Thanks!

Jinming-Hu commented 3 years ago

Mocking is never considered during the API design. So you might want to try to use some storage emulator like Azurite