Testing

Why test?

Test language

tcl

Simple tcl program


set n 1                              # assignment
set product 1                        # assignment
while {$n <= 10} {                   # loop - note spaces
                                     # before/after <=
    set product [expr $product * $n] # evaluate an expression
    incr n                           # increment n
}
set product                          # print product

Simple Java class for testing


public class Sum {
    private int total = 0;

    public void add(int n) {
        total += n;
    }

    public void subtract(int n) {
        total -= n;
    }

    public int getSum() {
        return total;
    }
}

Jacl tests


package require java

set sum [java::new Sum]

$sum add 10
$sum add 20
set total [$sum getSum]

if {$total == 30} {
    puts "test passed"
} else {
    puts "test failed"
}

Running the test program

Tcl tutorial

A tcl tutorial is at http://www.sftw.umac.mo/~fstrpba/tcltut/

Java extensions to tcl - jacl

There are a number of additional commands to handle Java objects. These include

A test framework

Test file format