I think, therefore I blog

How To Get The HTTP Status Code In Selenium WebDriver

By , 16 November 2012

How To Get The HTTP Status Code In Selenium WebDriver

One of the first things you'll notice when you start testing your web application with Selenium WebDriver is that there is no API to get the HTTP status code for a page. If you want to know why, you can go and read WebDriver issue #141. Personally I don't care why - I just want to test my HTTP reponse codes (especially 403 Permission Denied).

There is a fairly simple workaround you can use for WebDriver, but firstly lets look at how to do it without WebDriver. Nobody said you HAVE to use Selenium right?


9 comments, post a comment!

How To Sort Your Unit Tests By Layer In TestNG

By , 11 October 2012

How To Sort Your Unit Tests By Layer In TestNG

Each of my unit tests extends from a different base class depending on what layer of my application they are testing. i.e.

 `- BaseDBTest
     `- BaseOpsTest
         `- BaseUITest

These superclasses are very convenient places to put shared test code like starting a server, opening the database, doing a HTTP get or even just checking that assert is enabled.

When testing the whole application, it doesn't make much sense to me to run tests from all layers in random order. There are clear dependencies between the layers and if a lower layer fails I want to know about it before it blows up into the upper layers (if you believe its better to mock unit test dependencies then you might as well stop reading now).


2 comments, post a comment!

How To Unit Test Private Methods

By , 19 September 2012

How To Unit Test Private Methods

I've discovered that one reason I don't write as many unit tests as I should is because they live in a separate source tree, out of sight and out of mind. So I've moved my unit tests to be inner classes on the classes they test. A side effect of this is you can easily test the private methods of a class since the inner class has direct access to these methods.

Here is the configuration you will need to do this. Note, I am using TestNG, but it should be pretty similar in JUnit.


7 comments, post a comment!

Levels of Software Specificity

By , 28 September 2008

Why would you start at the bottom of this chart? People seem to do it all the time:

hmmmm... that seems like a good idea. i can whip it up in no time. okay, i guess i should test this. hey it did something! but, hang on i didn't really want it to do that. if i just change this i can get it to do something else. ouch! now the first bit broke, but i might still be able use it to if these conditions hold true. that's still useful isn't it? it could happen right? wait. hang on, what the hell are we trying to do again?

Repeat ad nauseum.

No comments yet, be the first to comment!

Maven and TestNG

By , 8 November 2006

I'm fairly new to maven, but so far it has really impressed me with its simplicity, productivity gains and IDE independence. So I was really looking forward to porting some unit tests to TestNG, running mvn test and watching in awe as maven found my tests, ran them and generated a pretty html report of the test results. Unfortunately, it didn't turn out quite like that.


4 comments, post a comment!


Join Over 1000 Subscribers

I write every Sunday about travel, psychology, and technology. Thousands of people just like you have already subscribed—and for good reason. It'll change your life. And it's free :)

Read a Good Book

“A spellbinding true story of love, passion and adventure. One can’t help but be swept away by 100% Love Guaranteed.” —Dr Tammie Matson, author of Elephant Dance.

Chat For A While

Your Vote Matters

Which animal will take over when humans go extinct?