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.
Printable View
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.
Is this the same with the Assertions in JUnit?
If so, then yeah... very useful. ;)
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.
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
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.
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.
They are read and compiled. But they are marked specially, so that the class loader can ignore them.
Thank you.