And one more for you:
Do you use the Assertion framework defined in java language? If so than what for?
I kind of have a problem with this, since the first time I ran into this assertion functionality was way back when only JUnit had this implemented. And I have to admit that it is the most simple and powerful code FOR UNIT TESTING.
Now that we have assert keyword in Java, I still do not see the point of having an assertion in the regular code instead of a simple if statement.
Now let me demonstrate one thing. Which is more readable?
public MyClass(String name) throws IllegalArgumentException{
if(name == null){
throw new IllegalArgumentException("Name cannot be null");
}
// the rest of the code
}
or
public MyClass(String name) {
assert (name != null);
// the rest of the code
}
Another thing, which of the above examples will imply the necessity of defining the thrown Exception in the javadoc? That leads to my previous post How Not to Write Java Documentation…
Well, I personally like the first approach (You know I am kind of old fashioned).
As much for the using the Assert (as junit.framework.Assert) class from JUnit framework in a class not belonging to a test case, I only can say: Oh nooooooooo!!!
JUnit is meant ONLY for module testing purpose(at least I like to consider this), and not for regular java code usage. It is kind of mixing apples with oranges…or something.
And now read the article of Misko Hevery posted on Javalobby: http://java.dzone.com/articles/assert-or-not-assert
Happy coding,
N