• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • 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,
 
Marshal
Posts: 17010
298
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.
 
author
Posts: 799
5
  • 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:

http://agileinaflash.blogspot.com/2011/11/test-abstraction-smells.html

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.

Regards,
Jeff
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic