|
-
Nov 17th, 2004, 02:57 AM
#1
Thread Starter
Dazed Member
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.
-
Nov 18th, 2004, 08:59 PM
#2
Banned
Is this the same with the Assertions in JUnit?
If so, then yeah... very useful.
-
Nov 18th, 2004, 10:10 PM
#3
Thread Starter
Dazed Member
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.
-
Nov 22nd, 2004, 07:04 AM
#4
Addicted Member
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
-
Nov 22nd, 2004, 08:59 AM
#5
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.
-
Nov 22nd, 2004, 05:44 PM
#6
Frenzied Member
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.
-
Nov 23rd, 2004, 04:10 AM
#7
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.
-
Nov 23rd, 2004, 06:10 AM
#8
Frenzied Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|