Login
Unit Test. Кто использует?
1707 просмотров
Перейти к просмотру всей ветки
in Antwort bobkov 29.10.16 23:37, Zuletzt geändert 30.10.16 17:56 (Программист)
По моему скромному мнению, надо покрывать Unit-тестами часто используемые функции (если в ООП, то классы).
Интересно, как определить это "часто"? Где граница?
Вот например такой код:
public interface Content
{
string GetContent(string path);
}
public class HttpContent : Content
{
public string GetContent(string url)
{
string content = null;
// Open connection
// download some information
// Close connection
return content;
}
public byte[] GetBinaryData(string url)
{
byte[] buf = null;
// Open connection
// download binary data
// Close connection
return buf;
}
}
public class DiskContent : Content
{
public string GetContent(string url)
{
string content = null;
// Open file
// read file
// Close file
return content;
}
}
public class SomeTool
{
public Content Content { get; private set; }
public SomeTool(Content content)
{
Content = content;
}
public string GetContent(string path)
{
return Content.GetContent(path);
}
}
public class SomeOtherClass
{
public SomeTool Tool { get; private set; }
public SomeOtherClass(Content content)
{
Tool = new SomeTool(content);
}
public string GetUserInfo()
{
return Tool.GetContent(@"some path\user");
}
public string GetFirmInfo()
{
return Tool.GetContent(@"some path\firm");
}
public string GetProductInfo()
{
return Tool.GetContent(@"some path\product");
}
}
Очевидно, что часто используемая функция тут SomeTool.GetContent (на нее идет целых 3 ссылки). Вот только надо ли ее тестировать? :)
Сдается мне, что оценка количества вызовов - неработающая оценка.