❔ Writing tests for Minimal API that calls KeyVault and Azure
How can i write tests for a web app using minimal Apis.
The Docs say i have to use
WebApplicationFactory<Program>
but i can't create it bescause it tries to call KeyVault and Azure client'd also need to be set etc.
Is it possible to just add a mock keyvault into it?3 Replies
Check out this article, that should help you get started:
https://devblogs.microsoft.com/azure-sdk/unit-testing-and-mocking/
You should probably mock the KV client object, such that you never actually call Azure KV from your test code.
Remember to also have an integration test which does call KV, to ensure you got the glue code right.
Pavel Krymets
Azure SDK Blog
Unit testing and mocking with Azure SDK .NET
Learn how to reliably unit test your code that is using the Azure SDKs.
hmm thanks for the link . The part of keyvault that needs to be called just adds the values of keyvault to the configuration. Not injecting Keyvault itself. No idea how to mock that
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.