This page discusses some of the details of writing Java tests with Tcl. For information about writing tests in general, see the Testing Tycho page.
TclBlend allows us to instantiate objects in a class and call public
methods. We use TclBlend and the standard Tcl test bed to create tests.
In the example below, we call java::new
to create an
instance of the Java NamedObj
class. We can then
call public methods of NamedObj
by referring to the
Java object handle $n
:
test NamedObj-2.1 {Create a NamedObj, set the name, change it} { set n [java::new pt.kernel.NamedObj] set result1 [$n getName] $n setName "A Named Obj" set result2 [$n getName] list $result1 $result2 } {{} {A Named Obj}}
test
subdirectory of the directory where the Java class
is defined.
For example, if we are testing NamedObj.java
, then
the Tcl test file should be at test/NamedObj.tcl
.
TclBlend provides a Tcl procedure called java::info
which returns information about an instance of a Java class.
$TYCHO/kernel/test/testDefs.tcl
defines the getJavaInfo
Tcl proc, which takes a Java object
handle and returns a string that describes the object's fields, methods
constructors, and superclass.
Each Java class should have a Tcl test that calls getJavaInfo
so that if the Java class definition changes, then the test will fail.
This will hopefully prompt the developer to write a test for the
changed feature.
Tycho Java Infrastructure
Tycho Home Page