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"
or:
"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.
I'm trying to standardize on test labels that use affirmative language to say what should have happened if everything went correctly, like "Connected to database using valid username and password" or "Failed to connect to database using invalid username".
The short identifiers might make sense to you, but they won't make sense to anyone else who starts working on your project.
The longer one. Definitely.
Definitely the longer names are better. Even though tests aren't really documentation in the sense that many people think of them, they can serve that role if well-handled. For example, I have a test method in my current project which just checks to ensure that a normal user cannot access the "admin" page and that they'll be sent back to the login screen. Here's what you see if you run that test method:
This narrative style of test names gets us a lot closer to tests as documentation. The test names describe the behavior in a way that the actual code does not. So if I had omitted the test names, here's what the code would have looked like:
In other words, you can kind of get a sense of what's going on, but the descriptive test names allow anyone to return to this months later and instantly know what's going on and why, rather than trying to parse code.
Hmm, this should be a top-level blog entry. Thanks for the idea :)
@Ovid: you're welcome. Thanks for the follow-up post. I think I'm converting :-)