• 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 ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Pragmatic Unit Testing in Java 8 with JUnit: test smells

Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good evening,

Can you give a sneak preview of the test smells by elaborating the topic for the ranchers?

We won't tell

I'm curious to know more about them.

Kind regards,
Posts: 17644
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The one that I like is "Missing Abstractions" - I deal with this all the time and it demonstrates the need to become sensitive to what the code, include test code, is telling you. For example, this test code:

has a "missing abstraction" smell to it. Don't detect it? Well, consider this variation:

Can you spot the missing abstraction now? This seems like a simple thing when you read it in a book but in practice, developers who are not sensitive to this kind of smell will just blow past it like nothing was amiss. The thought that it might need some refactoring will never even cross their minds.

One of the most frequent refactorings I use is "Rename" - anyone who knows me around here can tell you that good names are one of my biggest "things". A good name can lead you in the right direction; a bad name can hurt, confuse, and cause you endless amounts of pain. I'll have to think of a way to demonstrate how a test smell can reveal a bad name. I just know that I've done this enough to know when the test is telling me that we are looking at a bad name. I don't think I see that in Jeff's book though.
Posts: 799
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Greetings Yvette--

This "Agile in a Flash" card overviews the test smells:


It links to a PragPub article where Tim Ottinger and I take a difficult test method, and whittle it down into something reasonable.

I thought it was effective to see the distinction between a tests whose maintenance value is low, and one that can act as reasonable documentation on class capabilities. So I ended up repeating the concept in the book--i.e. you'll see another example of cleansing a test.

If you google about, you'll note that there are probably quite a few differing collections of "test smells." The book xUnit Test Patterns, for example, offers its own list. I don't think there's a canonical list, and I fear I'm muddying the waters a bit :-), but I've found it useful to strive to stomp out these smells.

With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic