Ayende @ Rahien

My name is Oren Eini
Founder of Hibernating Rhinos LTD and RavenDB.
You can reach me by phone or email:


+972 52-548-6969

, @ Q c

Posts: 6,026 | Comments: 44,842

filter by tags archive

Why you should test code too silly to break

time to read 1 min | 183 words

I wrote a test for this piece code:

public virtual void View([ARFetch("id")]Webcast webcast)
    PropertyBag["webcast"] = webcast;

Now, this looks like utter lunacy, isn't it? Especially when the test looks like:

public void When_view_called_will_send_webcast_to_view()
	var webcast = new Webcast();


Except that now that I have covered the very basic item, I now have another few tests:

public void When_view_called_with_null_webcast_will_render_missing_webcast_view()


public void When_view_called_with_unpublished_webcast_will_render_unpublished_webcast_view()
	controller.View(new Webcast());


And the simplest thing that can make those test pass is:

public virtual void View([ARFetch("id")]Webcast webcast)
        PropertyBag["webcast"] = webcast;

By having tests from the beginning, even for trivial piece of code, I ensured both that the trivial case will work and that I am already starting with the right tone.


Shawn Neal

If that's silly, then I guess I do silly things too. Confirming items get populated in the property bag or the correct view gets selected is actually relevant IMO, especially when it comes time to refactor/change the controller. My tests like that have saved me before, especially when you consider the cost of writing the tests is really low.

Alex Simkin


"I wrote a test for this piece [of] code:"

If you wrote test first there would be no question.

Mickael Sauvee

These lines of code are not siily as they implement some "behaviour" ... or desired features. I agree they have a very low risk to break... unless a full rewrite which has a higher risk to occur :-)

Comment preview

Comments have been closed on this topic.


No future posts left, oh my!


  1. Technical observations from my wife (3):
    13 Nov 2015 - Production issues
  2. Production postmortem (13):
    13 Nov 2015 - The case of the “it is slow on that machine (only)”
  3. Speaking (5):
    09 Nov 2015 - Community talk in Kiev, Ukraine–What does it take to be a good developer
  4. Find the bug (5):
    11 Sep 2015 - The concurrent memory buster
  5. Buffer allocation strategies (3):
    09 Sep 2015 - Bad usage patterns
View all series


Main feed Feed Stats
Comments feed   Comments Feed Stats