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 naïveté. 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.

[Advertisement] BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!