Article 20NWD CodeSOD: A Type of Test

CodeSOD: A Type of Test

by
Remy Porter
from The Daily WTF on (#20NWD)

Unit tests are a wonderful tool for proving that your code works. Ideally, when you're using other code, like say, the .NET Framework, you don't write tests that test the framework itself. After all, didn't Microsoft already do that?

David T's co-worker laughs at your naiveti(C). 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<DateTime>()); }

Now, if the .NET Framework's ability to load and recognize types ever breaks, David's team will be the first to know.

buildmaster-icon.png [Advertisement] Application Release Automation - build complex release pipelines all managed from one central dashboard, accessibility for the whole team. Download and learn more today! TheDailyWtf?d=yIl2AUoC8zA4aw6-Oo8va0
External Content
Source RSS or Atom Feed
Feed Location http://syndication.thedailywtf.com/TheDailyWtf
Feed Title The Daily WTF
Feed Link http://thedailywtf.com/
Reply 0 comments