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

assertion

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if i tried to run assert false:false;
its saying
Exception in thread �main� java.lang.AssertionError: true
at Test.main(Test.java:3)

i thought that in simple assert statement the first expression should be a boolean, but here its seems that it should be true, and if our assumption is false then assertionError occurs.

is am right please someone explain.

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

The second expression is the value which is added to the stack trace when assertion fails . so you would get only "false" as your assertion will always false.I'm wondering how you got "true" as in

Exception in thread �main� java.lang.AssertionError: true
at Test.main(Test.java:3)



Correct me if I said something wrong

greetings
Parthiban
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by rahul R khanna:
...if our assumption is false then assertionError occurs...


That part is correct. You are asserting (assuming) that a boolean condition is true. If it turns out to be false at runtime, then an assertion error is thrown.

However, Parthiban is also correct in pointing out that the second expression is passed to the error message, so if you use assert false : false; then we would expect the first "false" to cause the error to be thrown, and the second "false" to appear in the error message. So I don't see how "true" is showing in the error message.
 
Bras cause cancer. And tiny ads:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic