testing

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/Bookmark

testing

Comments (0)

Permalink

Easy? Mock

Just writing a test case for a method that is a effectively a controller, it retrieves data from one class and uses another class to convert it to a different kind of object.

Easy mock makes it hard to test each interaction in isolation.

also anyway its a pain.

See here:

http://code.google.com/p/mockito/

for a better way!

nice1 Szczepan

  • Share/Bookmark

testing

Comments (0)

Permalink