Login

Login
  • Register
  • VectorDesign blog

    Testing Automation and general Tech Geek stuff

    Assersion vs IF ElSE Statement

    Posted in java on 31 August 2017 by vectordesign

    The main thing you should keep in mind is that the if-else statement should be used for program flow control and the assert keyword should only be used for testing purposes. You should never use asserts to actually perform any operation required for your application to work properly. According to Sun’s official Java documentation: “Each assertion contains a boolean expression that you believe will be true when the assertion executes.” For example, if you have a method which is supposed to return a double value in the range [-1.0,1.0], you can use the following two statements to test this: assert value <= 1.0; assert value >= -1.0; If either of these assertions returns false, an error will be thrown to let you know there’s a problem.

     

    from http://www.answers.com/Q/What_is_the_difference_between_assert_keyword_and_if_keyword_in_java#ixzz1v2GGfAhq

    Leave a Reply