One of the most common examples of where we can drop an imperative verb prefix on a method name is in testing.

Unless a framework — such as pytest — requires 'test', such a prefix serves no useful purpose. It qualifies as a noise word, simply repeated what we already know from annotations/attributes, context, etc.

Stepping away from the imperative mood frees up the name (and the developer) to focus on naming a test more in terms of intent and purpose than as a directed action.

There are a number of popular naming styles that, for all their variation, often lead to names that contain the same information.

For example, the propositional style that I advocate (describe a property or behaviour using an indicative sentence), the BDD 'should' style, the more emphatic 'must' style, Roy Osherove's style (UnitOfWork_CallContext_Result), the long form Given-When-Then style, etc.

One thing they all share is fully informing the reader of what they can expect.

Whatever style you prefer, a useful guideline is to ensure that the name includes the form (but not necessarily the humour) of a joke: it should have a set-up and a punchline. Many test names have either a set-up (they tell you what is being tested and in what situation) or a punchline (they focus on outcome), but miss the other part (you don't know what outcome you're expecting or what leads to an outcome).

Test names? They're a joke 🙃

@kevlin with functional frameworks like Jest and Pest, I like using `describe` blocks to explain the conditions, and `it` to declare the outcome.

The test name is output to the console like:

given condition x > when event y > should do z

@paulshryock Yes, that works well when the shape of the code aligns well with grouping them like that, but can fragment when the outcome or the action offers a better grouping.

In those cases, I would favour using 'describe' for the outcome (the 'then') or action (the 'when'). For this reason I prefer 'test' over 'it'.

@kevlin I prefer Chris Stevenson’s TestDox, treat the object under test as the subject of a sentence. A basket:
- is empty when created
- returns items in the order they’re added
- totals up its items
- fails if you ask for an out of range item
- etc
@sf105 This style is an application of the propositional approach and satisfies the joke criterion
@sf105 @kevlin Whatever happened to the JetBrains TestDox plugin? I did briefly look at taking it on & updating it yonks ago but got distracted
@sf105 @kevlin <fires up computer to see if it’s been updated to the latest IDE… >
@kevlin I like the newspaper headline style 🙂
@kevlin, yeah. Though I wonder if, as humans, we need some phatic language even when relating to computers.
@punkstarman My experience on this particular matter suggests no, we don't. We're more capable than we give ourselves credit for.
@kevlin, somewhat agreed.
Yet there are cases in tech where overlooking linguistic pragmatics has led to disastrous consequences. The chief example would be the Like button.
@kevlin TBH I find no value in giving names to tests

@kevlin

Here's a suite for testing the parser in the editor I develop. None of the tests is named:

https://github.com/panicz/grasp/blob/main/src/test-parser.scm

Here's a test suite for editing. None of the tests is named:

https://github.com/panicz/grasp/blob/main/src/test-editor-operations.scm

Here's a regression test suite. None of the tests is named:

https://github.com/panicz/grasp/blob/main/src/test-regressions.scm

and so on.

I don't see how adding names to those tests would add any value.

grasp/src/test-parser.scm at main · panicz/grasp

The GRAphical Scheme Programming Environment. Contribute to panicz/grasp development by creating an account on GitHub.

GitHub
@kevlin of course, this is largely because the value of those tests comes from the quality which perhaps phenomenologists would call "givennes" or "sensual immediacy" (and for which I think most people have no name)
@kevlin We had a convention (for a limited time) to start the test methods with "test_that" (we use pytest) as a trigger to describe what you are expecting rather than what you are testing. So "test_that_sum_is_commutative" rather than "test_plus". After a while we dropped the convention and started writing "test_sum_is_commutative". Still have those "that"s lying around some places though.

@Haskellelephant A naming practice I think I may originally have been responsible for creating! I still often advocate for getting into the habit of naming things propositionally when 'test' is a mandatory prefix, or — to be precise — to get out of the habit of flat, directive-based naming.

But once you're out of the old habit and the new one is natural, all is good 🥂