在单元测试期间,ApplicationSettingsBase 在哪里保存配置文件?
一些背景上下文: 我从 ApplicationSettingsBase 派生来在我的应用程序中保存自定义配置设置集,并且手动测试工作正常,配置集的保存没有问题。
我还想对我的 ConfigSettings 功能进行单元测试,以确保反序列化和保存多组设置(使用各种 SettingsKeys)都正常工作。我选择的单元测试框架是 NUnit。
我的 TextFixtureSetUp 方法如下所示:
var configSettingsTest = new ConfigSettings("TestSettings");
configSettingsTest.Name = "TestName";
// ...lots of other initializations...
// Serialize the data
configSettingsTest.Save();
在我的实际应用程序中,看起来配置设置保存在
"<user>\AppData\Local\<myApplication>\<crazyHashKey>"
但我似乎找不到在单元测试中保存设置的位置。我的意思是,测试成功了,因此反序列化(大概)正在工作,但我不知道它们到底被写入磁盘上的哪个位置,并且 ApplicationSettingsBase 类似乎没有任何方法来指定保存路径。
有人有什么想法吗?
马特舒伯特
更新
我发现发生了什么事。我使用 Resharper 从 Visual Studio 中运行我的 NUnit 测试,并且 Resharper 创建了自己的独立 AppDomain。因此,ConfigSettings 被保存在
"<user>\AppData\Local\JetBrains\<crazyHashKey>"
(JetBrains 是 Resharper 背后的公司)
中,我使用命令行中的构建脚本对此进行了测试,发现 NUnit 做了类似的事情,因此 ConfigSettings 现在位于
"<user>\AppData\Local\NUnit.org\<crazyHashKey>"
希望这可以帮助其他有类似问题的人! :)
Some background context:
I'm deriving from ApplicationSettingsBase to save custom sets of configuration settings in my application, and the manual testing is working fine, the config sets are being saved no problem.
I also wanted to unit test my ConfigSettings functionality to ensure that both de-serialization and saving multiple sets of settings (using various SettingsKeys) are working. My unit test framework of choice is NUnit.
My TextFixtureSetUp method looks like this:
var configSettingsTest = new ConfigSettings("TestSettings");
configSettingsTest.Name = "TestName";
// ...lots of other initializations...
// Serialize the data
configSettingsTest.Save();
In my actual application, it looks like the config settings are being saved in
"<user>\AppData\Local\<myApplication>\<crazyHashKey>"
But I can't seem to find where the settings are being saved in my unit tests. I mean, the tests are succeeding, so the de-serialization is (presumably) working, but I have no idea where exactly they're being written to on disk, and the ApplicationSettingsBase class doesn't seem to have any way to specify a Save path.
Anyone have any ideas?
Matt Shubert
UPDATE
I found out what was happening. I was using Resharper to run my NUnit tests from within Visual Studio, and Resharper creates its own isolated AppDomain. So the ConfigSettings were being saved in
"<user>\AppData\Local\JetBrains\<crazyHashKey>"
(JetBrains is the company behind Resharper)
I tested this using my build script from the command line and found that NUnit does something similar, so the ConfigSettings were now in
"<user>\AppData\Local\NUnit.org\<crazyHashKey>"
Hope this helps anyone else who has a similar question! :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论