Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

use of assertions

 
Jan Groth
Ranch Hand
Posts: 456
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello,

i'm almost through with b&s, right now i'm only reviewing / refactoring / testing my code.

while developing, i used assertions once or twice, but neither consequently nor systematically (i have a set of unit tests instead).

the picture of my 2 or 3 assertions looks rather incomplete in my eyes. either i insert assertions with a consequent systematic approach, or i leave the whole thing away...

how are you handling this issue? using it consequently? not at all? sometimes?

any comments welcomed,

thanks a lot,
jan
 
Jan Groth
Ranch Hand
Posts: 456
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
bump.

nobody here using assertions in his code?
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12014
220
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jan,

I tend to rely more on unit tests and logging rather than asserts. I just looked at my assignment code, and found that I used 10 assert statements in 6 classes out of the 49 classes and interfaces that comprised the project.

For all three (unit tests, logging, and assertions) I recommend not deleting them once you have added them.

Regards, Andrew
 
Jesus Angeles
Ranch Hand
Posts: 2068
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i would use it only if it fits the tests that i want to do. But a println can do the same.
 
Jan Groth
Ranch Hand
Posts: 456
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@andrew

thanks for you reply. i was unsure wether it might be better to use an idea either consequently or not at all. anothing interesting metric from you post - i have 52 classes / interfaces, so it does look pretty comparable in terms of effort...

@jesus
"println" or not was not the question, i was referring to the assert statement from java 1.4 and higher. i would strongly advise not to rely on println for logging / debugging. you are missing a whole bunch of benefits, like configurable log levels and formats, different output channels and many other more...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic