Friday, November 16, 2007

If You Don't See It, Is It Really Gone?

Today's post is all about one of the surprisingly difficult tests:

If you test that something is not there, and you don't find it, did your test succeed or is your test broken?

Let's say, for example, that I want to test that a field is not present in the GUI. I fire up my IDE of choice and language of choice and write something like this*:

def test_field_not_present
    get :detail, {:type => "profile", :id => "1"}, {:user => "1"}
    assert_select "input#go_away_field", :count => 0

What I'm doing here is getting the page, and then checking that there are zero inputs with the id "go_away_field" (the field that shouldn't be there). Simple enough.

Here's the problem: I don't know whether the field is really not there or if there's an error in my test. Maybe I had a typo in my test and the field is still there.

I haven't figured out how to solve this one. Any ideas?

* The example is in Ruby. Choose whatever language you like.

1 comment:

  1. I would first test a situation when the test field is present, and then test the situation where the test field is not present. This way you can get pretty confident that the way your test is actually working.