Once you eliminate the simplest solution, whatever remains, no matter how improbable, might still be the simplest

I was pairing with Mollie today trying to help her with some test she had written that was giving a NullPointerException. It was one of those peculiar problem that looked straightforward to fix at first glance. However the more we looked at it together, the more our perspective changed.

At first glance we thought it was the before annotation not working. Seeing as I had spent the past 3 months and months before that with Ruby, I began forgetting some JUnit syntax. Mollie kindly reminded me that it’s “assertEquals()”. Did I forget to mention that we were using Vim? No Jetbrains helper here.

The asserts continue to fail anyhow, so I figured I would write a new test, that would simply test a String object equals to “hello”. How could that possibly fail? It passed, so now we knew it wasn’t the annotation. What could it be?

We continue researching, looking at different unit tests, when we looked at our tests, we noticed a glaring mistake.

public class TestClass

private app game;

@Before
public void setUp(){
Game game = new Game();

App app = new App(game);
}

@Test
public void TestGameStarts(){
app.Start();
assert.that(app.isStarted, is.equalsTo(true));
}

Yup! Clear as day when I look at it now. It’s obvious to me why we were getting an NPE.

Now I’m not sure why I didn’t see it straightaway. It could be that I was using ruby before looking at this code. It could be that I thought it was the environment setup(we were using vim) or simply it could simply be that I’m human sometimes we just don’t see these things straightaway. In either case I’ve yet been reminded that if someone asks you for help, start from the most obvious possible solution, then work your way up to the improbable.

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com 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