Test Naming

I was just naming some test cases.

I had a test called :

testShouldReturnInvalidSubmissionIfACompulsoryQuestionIsNotAnswered

I didnt like the way it had Return in it. THis is not very behavioural, it sounds like some implementation detail.

We have been using the pattern testShould a lot which i like, but here i thought, maybe i can call it:

testSubmissionShouldBeInvalidIfACompulsoryQuestionIsNotAnswered

Which breaks the pattern but looks ok. So i started renaming all the methods in the test. Halfway through i thought “what extra information is the ‘Submission’ word adding to my names ? And realised that actually my test was testing a class which was a submission validator and was returning a submission! do i really need to mention it all the time ? No!

so now its :

testShouldBeInvalidIfACompulsoryQuestionIsNotAnswered

all the tests are now named nicely and more concisely.

Share