喜上單元測試的預期值我是新的,我寫這個定位單元測試方法,但我不知道什麼是它的預期值。應該是什麼在單元測試
下面是要測試的功能:
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