CS 1130: Transition to OO Programming
Module 1, Part 7
Specifications, Testing, and Debugging
Part 7 is about testing. But before one can test, one has to know what to test for —one has to know what a method or class to be tested is supposed to do. So, we discuss briefly the specifications of methods, fields of a class, and the class itself.
Since you have programmed before, you will know much of what we say here already, but a review won't hurt, especially of a topic as important as testing and debugging. Also, the use of a JUnit tester will probably be new to you.
1. Specifications of MethodsWeb Lecture
Comments: Each method should have a precise specification, indicating (1) constraints on calls of the method and (2) what the method does.
2. Assertions in Programs
Watch all 3 lectures on p. 1-6 of the ProgramLive CD.
Comments: An assertion is a true-false statement about the program variables that is placed somewhere in a program. By placing it in before or after a statement, one asserts that the assertion is true at that point.
3. Javadoc SpecificationsWeb Lecture
Comments: Comments of a certain form, beginning with /**, will be extracted and put on a web page. This allows the user to look at the specs without having to look at the Java program.
Comments: Testing is the process of running a program against "test cases" in order to get some evidence of the program's correctness. If a test case reveals an error, debugging (see points 6–7 below) takes place to find and correct the error.
5. JUnit TestingWb Lecture
Comments: DrJava provides a simple means for saving suites of test cases and executing them at will.
6. Debugging (Introduction)
Comments: If an error has been detected, it must be found and removed. This is called debugging.
7. Debugging Demonstration
Watch the two lectures on p. 14-4 of the ProgramLive CD
Comments: We give some pointers on inserting print statements and demonstrate how to find a bug.