Results 1 to 8 of 8

Thread: assertions?

  1. #1

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    assertions?

    Has anyone used these yet? As far as i understand them they are only supposed to be used within the development phase but can be kept in.

  2. #2
    Banned debbie_82's Avatar
    Join Date
    Jan 2004
    Location
    inside a hollow void
    Posts
    104
    Is this the same with the Assertions in JUnit?
    If so, then yeah... very useful.

  3. #3

    Thread Starter
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418
    JUnit sounds like an IDE. If it is and it's uses Jse 1.4 or later then it has assertions. I was just curious if anyone has ever used them. I just became aware of them recently.

  4. #4
    Addicted Member
    Join Date
    May 2001
    Location
    UK
    Posts
    222
    JUnit isn't an IDE as such, just a bunch of classes that can be used to test your own classes, by creating mock objects etc...

    they use assert to test assumption, i.e. you can assert (i == 10)
    if i does no equal ten then the assert throws an Error... here is a Sun webpage that explains how and why you should use them..

    http://java.sun.com/j2se/1.4.2/docs/...ng/assert.html

  5. #5
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    JUnit is a unit testing framework for Java.

    Assertions, the feature of Java 1.4, are a weird language construct (well, weird in the way they're implemented) to test simple things that you absolutely expect to follow some pattern to ensure that they really follow that pattern. Say, a function where you know exactly that null will never be passed, you could put an assert(arg != null) at the start. If you're not sure, do a proper check, or let the runtime throw a NullPointerException.

    Assertions will only be executed, loaded from the classfile even, if the VM is configured to do so. This means that they don't use any resources in a production release.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  6. #6
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111
    I know a little about assertions but not much. So maybe someone could tell me this: Are assertions actually comments, or are they really read by the compiler.

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    They are read and compiled. But they are marked specially, so that the class loader can ignore them.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  8. #8
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111
    Thank you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width