DumpsterDoggy

Articles

Search
Newest Articles
Recent Tutorials
Related Blogs
Get Microsoft Silverlight
Twitter Updates

Bookmark This

Sarcasm: Writing Tests Takes Such a Long Time!

Chris Missal, November 05, 2008

While working on one of my sites I wrote something I thought was worth sharing. This is one reason you should "test first" or adopt "TDD"... Whatever the case may be. I wrote these, which make obvious sense, but will drive my code to work the way I want it to work. I haven't even written StatRepository working yet.

  [Test]
  public void Ensure_that_MostPopular_Stats_are_arranged_in_a_valid_order()
  {
    var fakeStatRepository = new StatRepository();
    var popularStats = fakeStatRepository.GetMostPopularStats(5);

    var lastStatVoteCount = popularStats.Last().Votes.Count();
    var firstStatVoteCount = popularStats.First().Votes.Count();
    Assert.That(firstStatVoteCount, Is.GreaterThanOrEqualTo(lastStatVoteCount));
  }

  [Test]
  public void Ensure_that_Newest_Stats_are_arranged_in_a_valid_order()
  {
    var fakeStatRepository = new StatRepository();
    var popularStats = fakeStatRepository.GetNewestStats(5);

    var lastStatVoteDate = popularStats.Last().Votes.Count();
    var firstStatVoteDate = popularStats.First().Votes.Count();
    Assert.That(firstStatVoteDate, Is.LessThanOrEqualTo(lastStatVoteDate));
}

All the methods in StatRepository currently do is throw a NotImplementedException, but by writing this, I can now test them, watch them fail, then add the code to make them succeed. If somebody says they don't have time to write tests, it's because they've never done it, it doesn't take long.

Filed Under: Testing   C#