Azure的单元测试代码
我有一个Azure应用程序,最近去了应用程序设置的gung-ho。我意识到将几乎所有我需要的设置都放到ServiceConfiguration中是明显的办法,可以让你远程更改任何事情;这意味着Web服务URL,SMTP主机信息等都在我的ServiceConfiguration中。Azure的单元测试代码
可以想象我吃惊的时候,之后我做了我的变化,我试图运行我的200多个单元测试,只嫌直入这个错误:
Why am I getting SEHException when calling RoleEnvironment.GetConfigurationSettingValue("MYKEY")?
很显然,我在这里有几个选项。 ..
- 我可以使用RoleEnvironment.IsAvailable()来编写我自己的小类,以检查我应该从哪里获取设置,并从app.config获取它们,如果我不在天蓝色的话。
- 我可以将我的应用程序部署到测试环境,只需测试外部接口。
但是有没有“内置”方式?是否有更新的单元测试框架可以让我测试正在运行的确切代码(在将运行的环境中以及将要部署的设置中)?
您可以在测试项目的[Assembly Initialise]上运行模拟器。
ProcessStartInfo start = new ProcessStartInfo
{
Arguments = "/devstore:start",
FileName = @"C:\Program Files\Windows Azure Emulator\emulator\csrun.exe"
};
更多的这两个环节
可能有助于 http://andrewmatthewthompson.blogspot.nl/2011/12/deploying-packages-to-azure-compute.html
测试存储:http://www.neovolve.com/post/2012/01/12/Integration-testing-with-Azure-development-storage.aspx
这是一个有趣的想法!谢谢。问题出自前一阵子 - 所以,我为自己研究了一个可以接受的解决方案 - 但这对其他人希望做同样的事情并在搜索中遇到这个问题可能很有价值。 – Steve 2012-09-07 17:35:32
截至今年6月的2012 Azure的发布,可以使用CloudConfigurationManager - 它会检查.cscfg和.csdef文件(如果可用),否则从app.config或Web.config的appSettings部分读取:
<configuration>
<appSettings>
<add key="Foo" value="Bar" />
</appSettings>
</configuration>
然后在代码中:
CloudConfigurationManager.GetSetting("Foo")
我认为这是最好的方法 – SideFX 2013-10-25 16:40:27
按预期工作,感谢您的答案。 – morganw09dev 2018-03-01 21:17:31
这有帮助吗? http://andrewmatthewthompson.blogspot.nl/2011/12/deploying-packages-to-azure-compute.html你可以用这个测试存储:http://www.neovolve.com/post/2012/01/12 /Integration-testing-with-Azure-development-storage.aspx – 2012-09-04 15:00:11