嗨,我是单元测试的新手,我正在编写这个本地化单元测试方法,但我不确定它的预期值是多少。
这是要测试的功能:
public static string GetStringResource(string language, string name)
{
Localization cfg = GetInstance();
try
{
if (cfg != null && cfg._config != null)
return cfg._config.GetValue(language, name).ToString();
return string.Empty;
}
catch { return string.Format("Localization Error: '{0}:{1}' Not Found.", language, name); }
}
这是 GetValue 函数:
public override object GetValue(string section, string entry)
{
VerifyAndAdjustSection(ref section);
VerifyAndAdjustEntry(ref entry);
try
{
//XmlDocument doc = GetXmlDocument();
XmlElement root = doc.DocumentElement;
XmlNode entryNode = root.SelectSingleNode(GetSectionsPath(section) + "/" + GetEntryPath(entry));
return entryNode.InnerText;
}
catch { return null; }
}
这是我未完成的测试方法:
public void GetStringResourceTest()
{
string language = "English"; // TODO: Initialize to an appropriate value
string name = "John Smith"; // TODO: Initialize to an appropriate value
string expected = language; // TODO:" Initialize to an appropriate value
string actual;
actual = Localization.GetStringResource(language, name);
Assert.AreEqual(expected, actual);
}