CodeSOD: A Type of Test |
Unit tests are a wonderful tool for proving that your code works. Ideally, when youre using other code, like say, the .NET Framework, you dont write tests that test the framework itself. After all, didnt Microsoft already do that?
David Ts co-worker laughs at your na"ivet'e. Why would you trust Microsoft? You need to make sure the framework works as advertised. Which is why their unit tests are mostly made up of code like this:
[Test]
public void It_Converts_DataType_Text_Into_ConcreteType()
{
const string dataTypeText = "System.DateTime";
var dataType = Type.GetType(dataTypeText);
Assert.IsTrue(dataType == typeof(DateTime));
}
[Test]
public void It_Converts_String_Into_Given_DataType()
{
const string data = "10-10-2014";
const string dataTypeText = "System.DateTime";
var dataType = Type.GetType(dataTypeText);
object newData = Convert.ChangeType(data, dataType);
Assert.That(newData, Is.TypeOf());
}
Now, if the .NET Frameworks ability to load and recognize types ever breaks, Davids team will be the first to know.
| Комментировать | « Пред. запись — К дневнику — След. запись » | Страницы: [1] [Новые] |