Friday, December 26, 2008

Using Assert

Java 2 version added as new keyword to Java, assert. It is used during program development to create an assertion, which is a condition that it should be true during the execution of the program. For example, one might have a method that should always return a positive integer value. This can be tested by asserting that the return value is greater than zero using an assert statement. At run time, if the condition actually is true, no other action takes place. However if the condition is false, then an Assertion Error is thrown. Assertions are often used during testing to verify that some expected condition is actually met. They are not usually used for released code.

0 comments: