喜上单元测试的预期值我是新的,我写这个定位单元测试方法,但我不知道什么是它的预期值。应该是什么在单元测试
下面是要测试的功能:
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);
}
首先,什么语言?其次,如果你不知道这段代码的行为,为什么你会期待陌生人呢?编写单元测试是关于给定某些输入的测试行为。 – Makoto