• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Devaka Cooray
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
Bartenders:

Tests that tell a story (or using underscores in test names)

 
Sheriff
Posts: 17735
302
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[This post was split off from here: https://coderanch.com/t/777818/java/Mocking#3555275]

Some of the reasoning behind using underscores and making test names more readable:

- Tests should test a story - they should have a beginning, a middle, and an end. If you use JUnit nested classes, you can also structure the story told in the test report:

RestaurantTest
   OperatingHours
         should be open between opening time and closing time
         should not be open before opening time
         should not be open after closing time
   Menu
         should include drinks
         should include desserts
         should include lunch specials
         should include daily specials
   Reservations
         should allow reservation for current day
         should allow reservation for future date


- If your tests are going to tell a story, the test names should give you a "overall" view of that story.

- Tests should serve as examples for how to use the class under test. Tests should help you understand the API and its design.

- Tests should help you quickly find where problems are happening in your code
 
It would give a normal human mental abilities to rival mine. To think it is just a tiny ad:
The new gardening playing cards kickstarter is now live!
https://www.kickstarter.com/projects/paulwheaton/garden-cards
reply
    Bookmark Topic Watch Topic
  • New Topic