469,275 Members | 1,601 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,275 developers. It's quick & easy.

what is assertion in java?

what is assertion in java?
thank you
~ 股票價格有升有跌, 買賣*n能承擔*滅I ~

~ Samba, more than a low cost File and Printer server ~

-- Let us OpenSource --
Jul 18 '05 #1
5 20014

"SOAP" <s@soap.com> wrote in message news:42********@usenet.hk...
what is assertion in java?
thank you

verifying correct preconditions and post conditions for your methods so
testing your software will go more smoothly
Jul 18 '05 #2

The point is to verify your software is in a valid state.

For example if you KNOW the x should be greater than Y then you let your
program in on that knowledge:

assert ( x > Y)

This way if somehow y is greater than x your program tells you:

arrestion failed (x > y) line 4414.

SOAP wrote:
what is assertion in java?
thank you
~ 股票價格有升有跌, 買賣*n能承擔*滅I ~

~ Samba, more than a low cost File and Printer server ~

-- Let us OpenSource --


Jul 18 '05 #3
well the drawback of this is having your code cluttered with asserts all
over the place. it is possibly better to have a testing framework (like
junit) in place.

best regards,
jan

Hal Rosser wrote:

"SOAP" <s@soap.com> wrote in message news:42********@usenet.hk...
what is assertion in java?
thank you

verifying correct preconditions and post conditions for your methods so
testing your software will go more smoothly


--
______________________________________
insOMnia - We never sleep....
http://www.insomnia-hq.de
Jul 18 '05 #4
Jan Thom wrote:
well the drawback of this is having your code cluttered with asserts all
over the place. it is possibly better to have a testing framework (like
junit) in place.


JUnit and asserts are not exactly equivalent technologies. How can you
write a JUnit test that ensures that a particular method is never called
with a null value? (Certainly not in any way that JUnit is typically used.)

Having code with asserts can be very helpful, as it is self documenting.
If you see a method that takes a parameter x and you see an assert
that x is not null, you know that the caller is responsible for not
passing null values to the method. Asserts lay out the assumptions made
by the code that follows.

Ray

--
XML is the programmer's duct tape.
Jul 18 '05 #5
.... and a -assertion option can be specified to the compiler. If absent, the
assertions are ignored.
There's a good article here:
http://www.javaworld.com/javaworld/j...09-assert.html
/Jesper

"Hal Rosser" <hm******@bellsouth.net> wrote in message
news:nY****************@bignews6.bellsouth.net...

"SOAP" <s@soap.com> wrote in message news:42********@usenet.hk...
what is assertion in java?
thank you

verifying correct preconditions and post conditions for your methods so
testing your software will go more smoothly

Jul 30 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

220 posts views Thread by Brandon J. Van Every | last post: by
21 posts views Thread by Helge Jensen | last post: by
1 post views Thread by Timur Safin | last post: by
6 posts views Thread by Bhachi | last post: by
669 posts views Thread by Xah Lee | last post: by
4 posts views Thread by Mullai | last post: by
25 posts views Thread by Cromulent | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.