我喜欢这里的建议:单元测试解析器大字符串输入
它建议使用此代码:
public class SettingsReader()
{
public SettingsReader(System.IO.StreamReader reader)
{
// read contents of stream...
}
}
// In production code:
new SettingsReader(new StreamReader(File.Open("settings.xml")));
// In unit test:
new SettingsReader(new StringReader("<settings>dummy settings</settings>"));
我只是想知道最好的做法是“供应什么'大的测试字符串(即要解析的文件的几行)。
听起来很有趣。你可以添加一些更多的肉此为纽带,没有帮助。我非常感谢 – cs0815
好吧只是觉得:http://stackoverflow.com/questions/6080596/how-can-i-load-this-file-into-an-nunit-test – cs0815