Re: what is assertion in java?



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.
.



Relevant Pages

  • Re: what is assertion in java?
    ... well the drawback of this is having your code cluttered with asserts all ... it is possibly better to have a testing framework (like ... junit) in place. ...
    (comp.lang.java)
  • Re: Advice on how to remove dependency to framework
    ... JUnit is a testing framework. ... How on earth would anyone depend an ... earth would a programmer worth two cent not know what is wrong with ...
    (comp.lang.java.help)
  • Looking for a web testing framework
    ... Just as I use JUnit for server side unit testing (EJBs), ... I've searched for other web application testing framework and came up ... with JWebUnit which is JUnit built above HttpUnit. ...
    (comp.lang.java.softwaretools)
  • JUNIT very slow.......
    ... I have a small program I build as a stand-alone ... and as a junit test. ... I am using Apache Ant. ... When run as the Junit ...
    (comp.lang.java.programmer)
  • Re: JUNIT questions
    ... code (which is flawless and works). ... flashed red at me and this is where I'm stuck. ... Are you running your JUnit test case from inside an IDE? ...
    (comp.lang.java.programmer)