[Xswt-developer] new test project
Brought to you by:
dvorme
|
From: <ha...@id...> - 2006-07-04 15:48:05
|
Hi,
I've added a new project for testing and implemented two tests, as a =
start.
They both rely on methods in the XSWTTestCase class, which handles =
creating
the XSWT object, a Shell and using the Shell as the parent. Since the =
tests
require SWT, they must be run with the SWT applicaiton launcher, and =
invoke
a TestRunner manually. This requires a main method, which calls a =
utility
method in XSWTTestCase, as shown below. Two getChild methods are =
provided
for getting hold of Controls below the Shell in the widget hierarchy.
An XSWTTestCase assumes that there is a an XSWT file of the same name as =
the
test class, i.e. WidgetCreationTest.xswt for the WidgetCreationTest =
class
below. The content of this file is shown below. The XSWTTestCase class
provides setUp methods for reading the XSWT code from an InputStream or =
a
String instead. This requires overriding the no-arg setUp method and =
calling
one of the inherited ones.
Please critique the design! And if anybody knows how to make the =
launching
code more elegant, please enlighten me :-)
public class WidgetCreationTest extends XSWTTestCase {
public void testLabel() {
Label label =3D (Label)getChild(0, Label.class);
assertEquals("Label", label.getText());
}
=09
public static void main(String[] args) {
doRun(WidgetCreationTest.class);
}
}
<?xml version=3D"1.0" encoding=3D"UTF-8"?>
<xswt xmlns:x=3D"http://sweet_swt.sf.net/xswt">
<import xmlns=3D"http://sweet_swt.sf.net/xswt">
<package name=3D"java.lang"/>
<package name=3D"org.eclipse.swt.widgets"/>
</import>
<x:children>
<label text=3D"Label"/>
</x:children>
</xswt>
Hallvard Tr=E6tteberg (ha...@id..., http://www.idi.ntnu.no/~hal)
Associate Professor, IS group, Dept. of Computer and Information =
Sciences at
the Norwegian Univ. of Science and Technology
|