Thomas Sundberg

July 31, 2013

Is the parameter used?

Filed under: Java, Programming — Tags: , , , — Thomas Sundberg @ 19:57

This post has been migrated to

I watched a presentation by Zsolt Fabok a while ago and saw a technique I hadn’t thought of before. How do you verify that a parameter is used in a simple way? Feed the method with something that usually doesn’t work and verify that something happens.

Send in null and assert that you actually receive a NullPointerException like this:

@Test(expected = NullPointerException.class) public void shouldVerifyParameterUsage() { Example example = new Example();; }

There are other ways to trace a parameter or verify that it is being used, but this is a trivial way that often works. Similar to printf debugging. It is not pretty, but it is always available and works.



  1. Tracer bullets were described in The Pragmatic Programmer book by Andy Hunt and Dave Thomas. You can also read about it here:

    What you’re describing here doesn’t sound related at all.

    Comment by Aslak Hellesøy — July 31, 2013 @ 21:18

    • Hi!

      You are quite right Aslak. I rewrote it a bit.

      Thanks for the pointer.


      Comment by Thomas Sundberg — August 1, 2013 @ 02:54

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at

%d bloggers like this: