CodeSOD: Testing Your Date

"Don't unit test the library/framework code," is a good piece of advice. And yet, it's so often ignored.

Kaylee's co-worker certainly ignored it. They also ignored the basic principle of "ensure the test will work tomorrow."

[Test]
public void TestNewDate()
{
   String date = DateTime.Now.ToShortDateString();
   Assert.IsTrue(date == "26/08/2016");
}

Now, this test has been in the code base since 2016, as you might guess. It was not disabled or otherwise commented out. "But surely, their CI job would choke on it?" you might wonder. That assumes there is a CI job, and not a batch of tests that developers run manually, 70% of which pass and the remaining 30% have tickets in their ticketing software to get fixed "eventually".

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

This post originally appeared on The Daily WTF.

Leave a Reply

Your email address will not be published. Required fields are marked *