PDA

Click to See Complete Forum and Search --> : assertions?


Dillinger4
Nov 17th, 2004, 01:57 AM
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.

debbie_82
Nov 18th, 2004, 07:59 PM
Is this the same with the Assertions in JUnit?
If so, then yeah... very useful. ;)

Dillinger4
Nov 18th, 2004, 09:10 PM
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.

Andy_Hollywood
Nov 22nd, 2004, 06:04 AM
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/guide/lang/assert.html

CornedBee
Nov 22nd, 2004, 07:59 AM
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.

System_Error
Nov 22nd, 2004, 04:44 PM
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.

CornedBee
Nov 23rd, 2004, 03:10 AM
They are read and compiled. But they are marked specially, so that the class loader can ignore them.

System_Error
Nov 23rd, 2004, 05:10 AM
Thank you.