This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
Do you mean test your "MyException extends Exception" class, or test that your code throws an exception as expected? For the former, I usually test only that the stack trace the exception produces contains the pieces of information I expect it to contain (i.e. the most often the description given to the constructor at creation time). Something like: For the latter:
[ this post has been edited to remove the blatant advertising. Please visit the advertisement here ] [ March 15, 2004: Message edited by: Jessica Sant ]
Joined: Mar 15, 2004
For an example of how you would perform unittesting with Jtest, imagine that you have just written the fol- lowing Simple class in your IDE and you want to test it. Simple.java
To start the test, you tell Jtest to run the Generate and Run Unit Tests test scenario. Jtest examines the internal structure of the class under test, automatically generates and executes test cases designed to fully test the class's construction, then determines whether each test case's inputs would produce an uncaught runtime exception. In seconds, Jtest's test cases cover 100% of the class and identify one StringIndexOutOfBounds exception. [ Jess added UBB [code] tags to preserve whitespace, check 'em out! ] [ March 15, 2004: Message edited by: Jessica Sant ]