开发者

Unit Testing Code for Azure

I have an Azure application, and recently went gung-ho on the application settings. I realized putting pretty much every setting I needed into the ServiceConfigurat开发者_如何学Cion was the obvious way to go for anything you might even remotely want to change on the fly; which means web service URLs, smtp host information, etc is all in my ServiceConfiguration.

Imagine my suprise when, after I made my changes, I tried to run my 200+ unit tests, only to smack straight into this error:

Why am I getting SEHException when calling RoleEnvironment.GetConfigurationSettingValue("MYKEY")?

Obviously, I have several options here...

-I can write my own small class using RoleEnvironment.IsAvailable() to check where I should be getting my settings from, and get them from the app.config if i'm not in azure.

-I could deploy my application to the test environment, and just test the externally-facing interfaces.

But is there a "built-in" way? Are there any updates to the unit testing framework that would let me test the exact code that's running (within the environment it will be run in and with the settings that will be deployed)?


As of June 2012 Azure release, you can use the CloudConfigurationManager - it checks the .cscfg and .csdef files if available, otherwise reads from the appSettings section of app.config or Web.config:

<configuration>
  <appSettings>
    <add key="Foo" value="Bar" />
  </appSettings>
</configuration>

Then in code:

CloudConfigurationManager.GetSetting("Foo")


As far as I'm aware there is no built in way in the testing framework for testing which version of the config settings you should be using. I'm using a wrapper class like the one you describe (which I'm sure you already know is simple to write), but mainly so that we can run our websites outside of the dev fabric.


You could run the emulator on [Assembly Initialise] of the test project.

ProcessStartInfo start = new ProcessStartInfo 
{                                             
    Arguments = "/devstore:start",                                             
    FileName = @"C:\Program Files\Windows Azure Emulator\emulator\csrun.exe"                        
};

for more these two links might help http://andrewmatthewthompson.blogspot.nl/2011/12/deploying-packages-to-azure-compute.html

to test storage : http://www.neovolve.com/post/2012/01/12/Integration-testing-with-Azure-development-storage.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜