C#单元测试:写入设置在单元测试中不保存在user.config值 [英] c# Unit Test: Writing to Settings in unit test does not save values in user.config

查看:213
本文介绍了C#单元测试:写入设置在单元测试中不保存在user.config值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行一个C#单元测试(VS 2008)。内测试我写入设置,这将导致在将数据保存到所述user.config

I am running a c# unit test (VS 2008). Within the test I do write to the settings, which should result in saving the data to the user.config.

Settings.Default.X = "History"; // X is string
Settings.Default.Save();

但是这根本无法创建文件(我已经在交叉检查C:\ Documents和Settings \硬件\本地设置\应用数据)。

But this simply does not create the file (I have crosschecked under "C:\Documents and Settings\HW\Local Settings\Application Data").

如果我创建相同的东西,作为一个控制台应用程序,是没有问题的持久化数据(同code)。

If I create the same stuff as a Console application, there is no problem persisting the data (same code).

有没有我需要考虑的一个的UnitTest这样做一些特别的东西?

Is there something special I need to consider doing this in a UnitTest?

推荐答案

我尝试了与Visual Studio 2010的Windows 7和Visual Studio的单元测试框架实际上是创造了测试应用中,我发现我的用户临时文件夹。配置文件与正确的设置。我想可能是在VS 2008中同样的事情。 这些文件夹的路径方案是什么样的:

I tried it with Visual Studio 2010 on Windows 7 and the Visual Studio Unit Test framework is actually creating a temporary folder for test applications in which I found my user.config file with correct settings. I think it might be the same thing on VS 2008. The path scheme to these folder is of the kind:

的Windows Vista /七路径:

Windows Vista/Seven path:

C:\用户\ $ USER $ \应用程序数据\本地\ Microsoft_Corporation \ TestAppDomain {NUMBER}

C:\Users\$USER$\AppData\Local\Microsoft_Corporation\TestAppDomain{Number}

Windows XP的路径:

Windows XP path:

C:\ Documents和Settings \ $ USER $ \本地设置\ Microsoft_Corporation \ TestAppDomain {NUMBER}

C:\Documents and Settings\$USER$\Local Settings\Microsoft_Corporation\TestAppDomain{Number}

祝你好运。

这篇关于C#单元测试:写入设置在单元测试中不保存在user.config值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆