功能测试从 App_Data 文件夹获取文件
我正在编写功能测试,并且我正在编写测试的方法必须访问 App_Data 文件夹中的文件。我已经尝试过
System.Web.HttpContext.Current.Server.MapPath("~/App_Data/test.txt");
了,但
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "test.txt");
两者都不起作用。有没有办法在功能测试中实现这一点?
非常感谢这方面的任何想法。
谢谢,
拉贾
I am writing functional tests and the method I am writing the tests for has to access a file in the App_Data Folder. I have tried
System.Web.HttpContext.Current.Server.MapPath("~/App_Data/test.txt");
as well as
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "test.txt");
Both of them are not working. Is there a way to achieve this in functional test?
Any ideas in this regard is much appreciated.
Thanks,
Raja
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我终于找到了一个解决方案(在我的解决方案架构师的帮助下)。我们为功能测试项目设置了应用程序配置,并将文件名设置为应用程序设置之一。之后,我们将实际文件的相对路径指定为
测试类的属性。我们添加了一个简单的技巧,以便在测试(应用程序配置)和
未测试时使用绝对路径。该解决方案的逻辑是,由于我们将文件作为 DeploymentItem 放置,它会直接进入相应的 TestResults 文件夹,因此如果我们使用绝对路径,它将能够引用它。
希望这对某人有帮助。
I found a solution at last (with the help of my solutions architect). We set up an app config for the functional test project and we set the file name as one of the appsettings. After that we specified the relative path to the actual file as a
attribute for the test class. We added a simple hack to use Absolute Path if it is in test (app config) and
if it is not test. The logic to the solution is that since we put the file as a DeploymentItem it goes straight to the respective TestResults folder so if we use absolute path it is going to be able to reference it.
Hope this helps someone.