【发布时间】:2010-12-05 04:39:57
【问题描述】:
目标是在给定这些 Xml 文件中的一些数据的情况下运行一些测试。
如何在单元测试方法中轻松地将给定的 Xml 文件加载到 XmlDoc 中?
当前状态是:
XmlDocument doc = new XmlDocument();
string xmlFile = "4.xml";
string dir = System.IO.Directory.GetCurrentDirectory() + @"\Msgs\"
//dir is then the value of the current exe's path, which is
//d:\sourcecode\myproject\TestResults\myComputer 2009-10-08 16_07_45\Out
//we actually need:
//d:\sourcecode\myproject\Msgs\
doc.Load( dir + fileName); //should really use System.IO.Path.Combine()!
将路径放在app.config 中只是一件简单的事情吗?考虑到开发人员机器上存在不同路径的可能性,我希望避免这种情况。
问题:在单元测试方法中如何编写将给定 Xml 文件加载到 XmlDocument 中的算法?
【问题讨论】:
标签: c# visual-studio unit-testing filepath