This weeks lecture was presented by Michael Smith and targeted an introduction to testing and debugging. Initially was discussed when testing should begin in the Software Development process, the Design phase. As soon as the solution has been designed then tests for that solution can and should also be designed. During the implementation phase testing should be conducted as soon as compilation is complete. Documentation was also recognized early in the lecture as a key aspect of testing and debugging.

Pearl Of The Week: Types of errors in Programs:

  • Syntax Errors -> Mistakes in spelling or unclosed parenthesis etc. Compiler will find these errors, preventing completion of compilation until they are amended.
  • Execution/Run Time Errors -> Null Pointer Exceptions, Attempting to access arrays outside of bounds. Occurrence of these errors in Java will result in relevant exceptions thrown.
  • Logic Errors -> Project has been compiled and runs without error but behavior is not as expected.

We then explored some examples of how important testing and debugging is by reviewing some examples where the process was not done correctly.

Prevention vs Detection

  • Using software development techniques such as Encapsulation will reduce the likelihood of errors occurring.
  • Practices such as Modularization and Documentation will enable errors to be identified more easily.

Unit testing

  • Each unit of an application (methods, classes, packages) can be tested independently.
  • Good because errors can be identified earlier in development and test suites can be created and used repeatedly.

Testing Fundamentals

  • Understand what the unit should do, it’s contract.
  • Look for violations
  • Use positive and negative tests. Test inside and outside boundaries.
  • Document all results
  • Document a test strategy

Example of a test strategy:

  1. Create an Employee object with the default constructor
  2. Create an Employee object with the non-default constructor
    1. (a) with valid field values
    2. (b) with invalid field values
  3. Test all the get methods
  4. Test all the set methods
    1. (a) with valid arguments
    2. (b) with invalid arguments
  5. Test the display method

Regression Testing

  • Whenever a program is modified, it must be tested to ensure that the changes did not induce any errors.
  • Regression testing is the process of re-running every previous test after a change is made.

Finally we discussed Manual Walkthroughs, Verbal Walkthroughs, Using print statements and debuggers for alternate methods of testing and debugging. Again documentation was mentioned as a key point, Mike stating that it is one of the major differences between professional and amateur programming.

The tutorial following the lecture was again quite simple and more student left after only an hour or so. That being said I did get the chance to ask some important questions for the assignment and clarify some points that I was confused about. One such point was in regards to the this.statement and its use with constructed which one of my classmates discovered. It turns out that we had both misread the example code on Java’s tutorial, this was quickly identified by Michael.

[cc lang=”Java”]
public class Rectangle {
private int x, y;
private int width, height;

public Rectangle() {
this(0, 0, 0, 0);
}
public Rectangle(int width, int height) {
this(0, 0, width, height);
}
public Rectangle(int x, int y, int width, int height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}

}
[/cc]

In the example above, the confusing part is the second constructor:

After Michael’s explanation it was clear that the ‘two-argument constructor calls the four-argument constructor with two 0 values.