我写了一段在config文件中, 读取自定义配置节的代码。然后再写了一个测试方法。
请问各位,这样写测试方法是否合理?
个人觉得只是简单的调用一下,没有逻辑上的判断,并不能体现出单元测试的价值。================================读取config文件=======================================
public class SpConfigHandler: IConfigurationSectionHandler
{
object IConfigurationSectionHandler.Create(object parent, object configContext, XmlNode section)
{
// 创建自定义对象
SpConfigItem configItem=new SpConfigItem(); // 解析配置节中的xml
foreach (XmlAttribute attrib in section.Attributes)
{
if (XmlNodeType.Attribute == attrib.NodeType)
{
switch(attrib.Name)       
{         
case "dbms_type":   
configItem.DbmsType=attrib.Value;
break;                  
case "dbms_text":            
configItem.DbmsText=attrib.Value;
break;
case "type":            
configItem.Type=attrib.Value;
break;
//default:            
// throw (new Exception("Invalid attribute: "+attrib.Name));
}
}
}
// 返回自定义对象
return (configItem);
}
}
============================测试代码=================================
[Test] public void TestGetSpConfigItem()
{
configItem=(SpConfigItem)System.Configuration.ConfigurationSettings.GetConfig("SchemaProviders/SchemaProvider");
Console.WriteLine(String.Format("DbmsType:{0}",configItem.DbmsType));
Console.WriteLine(String.Format("DbmsText:{0}",configItem.DbmsText));
Console.WriteLine(String.Format("Type:{0}",configItem.Type));
}