M/F 2:30-3:20   
in Philips 101

CS 1130: Transition to OO Programming

Spring 2015

Part 6 . The Class Definition Part 8. API Packages

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.


Contents

1. Specifications of Methods

Web Lecture

Reading: Lecture Notes (Lecture Slides)
Gries/Gries, Sec.13.3.1, pp. 376–378.

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

Reading: Watch all 3 lectures on p. 1-6 of the ProgramLive CD.
Gries/Gries, Section 14.4.

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 Specifications

Web Lecture

Reading: Lecture Notes
Gries/Gries, pp. II.2, pp. 496–497; App. I.2.3, p. 486.

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.


4. Testing.

Reading: Lecture Notes (Lecture Slides)
Gries/Gries, Section 14.1.

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 Testing

Wb Lecture

Reading: Lecture Notes (Lecture Slides)
Gries/Gries, Section 14.2.

Comments: DrJava provides a simple means for saving suites of test cases and executing them at will.


6. Debugging (Introduction)

Reading: Lecture Notes
Watch the lessons on pp. 14–1 through 14–3 of ProgramLive.

Comments: If an error has been detected, it must be found and removed. This is called debugging.


7. Debugging Demonstration

Reading: Watch the two lectures on p. 14-4 of the ProgramLive CD
Example Case

Comments: We give some pointers on inserting print statements and demonstrate how to find a bug.