This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

What is a better practice?  RSS feed

 
Alexander Sales
Ranch Hand
Posts: 89
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One assert per test?

or

the other way around...

like for example :



or

 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37234
519
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alexander,
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.

 
Alexander Sales
Ranch Hand
Posts: 89
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, that's a good approach. Thanks Jeanne.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!