Humor and Tests?

Humor is a serious business. But is it possible that tests are funny? And if there is no fun in our work can we be motivated, happy and productive? (Hint – nooo…)

My opinion is that if these are HTML Unit tests they cannot be very funny. Especially if they amount to 17676. These large pieces of code are sad and boring and I imagine them executed in a quiet, dark room with lots of expensive machinery, cables, and small blinking lamps. For long days and nights mother classes fill gigabytes of useless logs and aggregated pictures are sent directly to stakeholders. Which in turn generate even grimmer electronic content. The lost kilowatt-hours may move a train instead. Pfuu…. What about low level tests? Well they are different breed. You can run them in seconds on your local machine while listening to your favorite music. Have you ever thought to make them even funnier by putting some jokes inside? No? Then read on!

Often we use test strings (e.g. test ID-s, names, currencies, etc.) and we monitor how these get processed by our code under test. Imagine that you are designing a new and powerful String concatenation Framework. You already created a PowerPoint presentation. It managed to convince your tech leads and architects that your string concatenation framework will transform the product from this:

image2016-2-12 17-1-56

Into that:

image2016-2-12 17-15-0

The only thing that you are missing is a test that will initially fail and then become green when the new framework is in place. So here is you first boring attempt to complete the unit test.

@Test
public void test()
{
  String s1 = "Hello, ";
  String s2 = "world!";
  Assert.assertEquals("Hello, world!", StringConcatFW.concat(s1, s2));
}

 

Now this is really boring to read! Let’s try again:

@Test
public void test()
{
      String s1 = "Q: What did the bird say after his cage fell apart?";
      String s2 = "A: 'Cheap, cheap!'";
      Assert.assertEquals(s1.concat(s2), StringConcatFW.concat(s1, s2));
}

This seems much better for the reader of your test. Let’s make another one. This one will check if the framework throws exceptions if the first argument is null:

@Test(expected=NullPointerException.class)
public void test()
{
   String s1 = null;
   String s2 = "Laziness is when a person doesn't fake that he's working.";
   StringConcatFW.concat(s1, s2);
}

 

Great, do you feel inSPIRED? In case you want to try… Do you know who is the biggest f*g**t in the world? Pac-Man of course – he eats balls until it dies!

Humor and Tests?
Tagged on: