Java Reference
In-Depth Information
The test of a graphical user interface is a very complex subject; here we
describe a simple approach. The test class TestGUI contains the test method
testSimple() that applies the same test case used in the previous prototype.
The test checks the text in the HTML pane using the same techniques as the
previous prototypes. Since the JEditorPane can modify the text introducing
or removing spaces, special care must be devoted to avoid spaces in the
expected substrings.
public class TestGUI extends TestCase {
public void testSimple(){
String source #
"// this is a test class...\n" !
"class TestClass {\n" !
" String an_attribute;\n" !
" public int a_public_attribute;\n" !
" public void a_method(int a_parameter){\n" !
" String s;\n" !
" s # \"string content\"; }\n" !
" private int another_method() { return 0; }\n" !
// creates the window
TestFrame window # new TestFrame();
// activate it
window.setVisible( true );
// set the source code
// simulate a click on the button
// get the text from the htmlPane
String result # window.htmlPane.getText();
// destroy the window
String[] expected # {
"<head>","<title>","Class: TestClass",
"<FONT","color # \"navy\"","TestClass","</FONT>",
"<FONT","color # \"navy\"","Public members:","</FONT>",
"<LI>","<FONT","color # \"green\"",
Search WWH ::

Custom Search