Kamis, 11 Maret 2010

Choosing test names

Which test names do you prefer?

"tong() method can connect to database"
"tong() method can disconnect from database"
"sha() method can delete an existing file"
"sha() method fails when deleting a non-existing file"


"tong 1"
"tong 2"
"sha 1"
"sha 2"

They are both rather extreme, but if I had to choose, I would still rather go with the shorter ones. I tend to treat test names more like unique IDs, and when things go wrong I just look up the actual test code.

I wouldn't mind verbose test names though if they can somehow be automatically generated (a future Google Translate project, perhaps?) from code, because they are just repeating what the code says.

To repeat myself, it's the DRY principle.

2 komentar:

  1. I tend to prefer more verbose test labels, but I also tend to parameterize my tests so that the label is generated from data.

    for my $t ( @tong_tests ) {
    my ($label, $args) = @$t;
    ok( tong($args), "tong() method can $label");

    That's sort of silly for just two cases, but once you start testing all sorts of inputs, it scales very nicely.

    -- dagolden

  2. @dagolden: Yup, I use data for test labels all the time :-)


Catatan: Hanya anggota dari blog ini yang dapat mengirim komentar.