How to name our Unit Tests

Connection - 10'

Imagine we want to test this method :

public static boolean isLeapYear(int year)

How would you name your first test ?

  • Ask attendees to note on a Sticky Note what is the name of their first test

  • Compare the different styles

  • What do they prefer (Dot voting)

Concepts - 10'

Tests names v1

yearsNotDivisibleBy4...
yearsDivisibleBy4ButNotBy100...
yearsDivisibleBy100ButNotBy400...
yearsNotDivisibleBy400...
  • Is it readable ?

  • What is the intent ?

Tests names v2

  • Is it more readable ?

  • What is the intent ?

Tests names v3

  • Intent is more clear, isn’t it ?

Tests names v4

  • Express what the class should be able to do

  • Read it as a full sentence : express a true business specification

  • You should avoid technical terms

Concrete Practice - 30'

  • Choose a Kata on Coding Dojo

  • Extract the Test Cases you want to write

    • Define the structure and naming of your tests

Conclusion - 10'

Imagine you use this naming technique during the next 6 months :

  • What has changed ?

  • Who else have noticed those changes ?

  • What are the impacts on your day to day ?

Resources

Last updated

Was this helpful?