Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes Testing and the fly likes What is a better practice? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "What is a better practice?" Watch "What is a better practice?" New topic

What is a better practice?

Alexander Sales
Ranch Hand

Joined: Feb 21, 2011
Posts: 89

One assert per test?


the other way around...

like for example :


Jeanne Boyarsky
internet detective

Joined: May 26, 2003
Posts: 30050

The idea of one assertion per test is to be testing one thing in each test. That may require one assertion. In your example, each of the three assertions is independent and makes sense to be in a separate test. The clue is that you have clear "business" types names for each test.

Consider this example:

I'm testing one business case/scenario although I happen to use two assertions. I might even refactor the assertions to another method to show they go together.

[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Alexander Sales
Ranch Hand

Joined: Feb 21, 2011
Posts: 89

yes, that's a good approach. Thanks Jeanne.
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: What is a better practice?
Similar Threads
Objects not the same after reading from XML
Refactoring Exercise
method names in jUnit
Can someone guide me through the Test-First Challenge?
How can I convert Decimal value to Packed Format