-
Notifications
You must be signed in to change notification settings - Fork 371
Azure Storage is still hard to unit test / mock #465
Comments
+1 in some instances we've proxied loads of the storage SDK with our own classes and interfaces, just so we can test some crucial parts of our systems. |
@kieronlanning I'm pretty sick of have a separate repo just with :/ Feeling like we're getting close though! |
Any thoughts about this discussion @pemari-msft or @erezvani1529 ? |
Hi @PureKrome, Apologies for the delay in response. Is there a reason you can't create a Mock CloudFileDirectory given the mocked share and the uri? We would like to confirm that for the sake of improving the current unit testing experience we will consider and apply your feedback about the virtual properties in our next breaking release 9.0. Thanks, |
Um, I think I'm already doing this, above??
Like that? Then I create the mocked share..
And finally, I need to get a reference to the root directory of this mocked-share ... so I can then return my mocked cloud directory...
is this what you ment? otherwise, can you provide some code that shows me what I'm doing wrong? |
Hi @PureKrome, Apologies since I think I misunderstood your original question. You are right, this method should be virtualized as well, as part of virtualizing all Get*Reference methods. So with this issue we are tracking virtualizing the below items:
Please let me know if there is anything else so that we can consider and add it to the list above. Thanks for your collaboration, |
FYI: I identified another sealed class in #514 |
Issue #514 was closed and I was told to use this issue to track unsealing of classes and virtualizing of methods for milestone 9.0 so I am including the relevant information that I had included in #514: I found one additional class marked as sealed which prevents unit testing: Here's a contrived example where I am prevented from mocking the storage account and also mocking the blob client created by this storage account
Can you please consider un-sealing the StorageAccount class in version 9.0? |
OperationContext also has one "sealed" too many. There should be a requirement to put a comment explaining why is something sealed so that PRs can weed out unneeded "sealed" (pretty much all of them). |
aye! here here! Caused heaps of PITA. |
I disagree with this one. There is a good reason for using However, as a general rule you need to make sure that the SOLID Principles are kept:
Classes like |
Currently writing some functions which uses Azure Storage accounts and would like to be able to do some mocking; any news on when this will be released? Looks like Milestone 9 is 4 days overdue with 18 open issues :) Any ETA on this? |
Hi @DiaAWAY, We are waiting on a breaking service version release for this version to be out. The current planned date is mid-January. (We do not want to break twice as the new service version includes some breaking changes so we are bundling them together :) ). Thanks, |
We have released package v9.0.0 with a few improvements for mocking. Thanks again for your feekback 👍 ! Please share any other feedbacks so that we can include them in our split packages (Blob, Queue, File) (currently in preview, hence no need to wait for major version release) for faster delivery. Thanks! |
@erezvani1529 What sort of improvements? Looking at the changelog.txt in GitHub, I can't see anything relevant to mocking... |
Please checkout the BreakingChange list to find out about these improvements. Thanks |
@erezvani1529 Gotcha, thank-you. |
Is returning |
Hi Azure Storage team!
(question editted with extra info, about 10 mins after posting this).
This question is a continuation of #349, #318 and sorta #80
With release version
8.*
of the Azure SDK more methods have beenvirtualized
. Yay! better unit testing :)But ... I'm not having much luck with some stuff still -> mainly when I need to access a property .. which relys on some internal magic ... like the
Name
of aCloudFile
orCloudDirectory
, etc. This is because theconstructors
require specific arguments passed in (I believe).I think we might need some more things
virtualized
=> I thinksss
needs to be virtualized.So .. given the latest
8.*
version of the SDK, how could this simple piece of code be Unit Tested?Here is the code I wish to test: Given a
Share
in my Azure File Storage, list all the folders that exist in that share.Here's my code which I believe does this...
Here's a start of some unit testing code to help kick start things to make your life easier :
Problem: Because we cannot mock the
GetRootDirectoryReference()
method, a realCloudFileDirectory
instance is returned. Which means it will do real hits to the storage endpoints. Not kewl 😢So - could we please add
virtual
toGetRootDirectoryReference()
please?Side Point: would also love the properties also made virtual also 👍 Like
Name
etc...NOTE: I know this feels like a StackOverflow question, but I wanted to ask here because I'm really asking if the SDK has been designed enough to handle unit testing. Also, please do not suggest using the emulator in a unit testing (manual/local, CI/CD scenario's) situation please.
The text was updated successfully, but these errors were encountered: