testing swing applications
<[email protected]> Wed, 26 May 2004 16:50:53 +0530
| Newsgroups | gmane.comp.java.junit.announce |
|---|---|
| Message-ID | <[email protected]> |
This is a multi-part message in MIME format.
------_=_NextPart_001_01C44313.81997CF9
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Hi,
=20
I tried testing swing application using JFC unit.I have a class named
myclass.The class has a textbox and a button named mybutton.
I have a test class Testmyclass ,which checks for the existence of a
button in myclass.I used findNamedComponent () method .But my testcase
fails.
Please let me know how to use this method findNamedComponent().
Let's say my testclass looks like this,
import junit.extensions.jfcunit.*;
import junit.extensions.jfcunit.JFCTestCase;
import junit.extensions.jfcunit.TestHelper;
import junit.extensions.jfcunit.JFCTestHelper;
Class Testmyclass extends TestCase{
private myclass mi=3D null;
private JButton clickme=3Dnull;
private JFCTestHelper helper =3D null;
=20
=20
=20
public Testmyclass( String name ) { =20
super( name ); =20
}
=20
protected void setUp() throws Exception {
helper =3D new JFCTestHelper(); =20
=20
=20
clickme=3D(JButton)
helper.findNamedComponent(myclass.class,"mybutton",0);=20
System.out.println(clickme); =20
System.out.println("iN setup");
flushAWT(); =20
}
public void testnotnull() throws Exception{
assertNotNull("Not found ",clickme);
//fails=20
}
protected void tearDown() throws Exception{
super.tearDown();
System.out.println("In tear down");
}
}
Please help.
Meera Ramachandran
=20
------_=_NextPart_001_01C44313.81997CF9
Content-Type: text/html;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
<html>
<head>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Dus-ascii">
<meta name=3DGenerator content=3D"Microsoft Word 10 (filtered)">
<style>
<!--
/* Font Definitions */
@font-face
{font-family:"MS Mincho";
panose-1:2 2 6 9 4 2 5 8 3 4;}
@font-face
{font-family:"Book Antiqua";
panose-1:2 4 6 2 5 3 5 3 3 4;}
@font-face
{font-family:"\@MS Mincho";
panose-1:2 2 6 9 4 2 5 8 3 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman";}
a:link, span.MsoHyperlink
{color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{color:purple;
text-decoration:underline;}
tt
{font-family:"Courier New";}
span.EmailStyle17
{font-family:Arial;
color:windowtext;}
@page Section1
{size:8.5in 11.0in;
margin:1.0in 1.25in 1.0in 1.25in;}
div.Section1
{page:Section1;}
-->
</style>
</head>
<body lang=3DEN-US link=3Dblue vlink=3Dpurple>
<div class=3DSection1>
<p class=3DMsoNormal><tt><font size=3D2 face=3D"Courier New"><span =
style=3D'font-size:
10.0pt'>Hi,</span></font></tt></p>
<p class=3DMsoNormal><tt><font size=3D2 face=3D"Courier New"><span =
style=3D'font-size:
10.0pt'> </span></font></tt></p>
<p class=3DMsoNormal><tt><font size=3D2 face=3D"Courier New"><span =
style=3D'font-size:
10.0pt'>I tried testing swing application using JFC unit.I have a =
class
named</span></font></tt><font size=3D2 face=3D"Courier New"><span =
style=3D'font-size:
10.0pt;font-family:"Courier New"'><br>
<tt><font face=3D"Courier New">myclass.The class has a textbox and a =
button named
mybutton.</font></tt><br>
<br>
<tt><font face=3D"Courier New">I have a test class Testmyclass ,which =
checks for
the existence of a</font></tt><br>
<tt><font face=3D"Courier New">button in myclass.I used =
findNamedComponent ()
method .But my testcase</font></tt><br>
<tt><font face=3D"Courier New">fails.</font></tt><br>
<br>
<tt><font face=3D"Courier New">Please let me know how to use this method
findNamedComponent().</font></tt><br>
<br>
<br>
<br>
<tt><font face=3D"Courier New">Let's say my testclass looks like =
this,</font></tt><br>
<br>
<br>
<br>
<tt><font face=3D"Courier New">import =
junit.extensions.jfcunit.*;</font></tt><br>
<br>
<tt><font face=3D"Courier New">import =
junit.extensions.jfcunit.JFCTestCase;</font></tt><br>
<br>
<tt><font face=3D"Courier New">import =
junit.extensions.jfcunit.TestHelper;</font></tt><br>
<br>
<tt><font face=3D"Courier New">import =
junit.extensions.jfcunit.JFCTestHelper;</font></tt><br>
<br>
<br>
<br>
<tt><font face=3D"Courier New">Class Testmyclass extends =
TestCase{</font></tt><br>
<br>
<tt><font face=3D"Courier New">private myclass mi=3D =
null;</font></tt><br>
<br>
<tt><font face=3D"Courier =
New"> &n=
bsp;
private JButton clickme=3Dnull;</font></tt><br>
<br>
<tt><font face=3D"Courier =
New"> &n=
bsp;
private JFCTestHelper helper =3D null;</font></tt><br>
<br>
<tt><font face=3D"Courier =
New">
</font></tt><br>
<br>
<tt><font face=3D"Courier =
New"> &n=
bsp; &nb=
sp; &nbs=
p;
</font></tt><br>
<br>
<tt><font face=3D"Courier New"> </font></tt><br>
<br>
<tt><font face=3D"Courier =
New">
public Testmyclass( String name ) =
{ </font></tt><br>
<br>
<tt><font face=3D"Courier =
New"> &n=
bsp;
super( name ); </font></tt><br>
<br>
<tt><font face=3D"Courier =
New"> }</font></tt><br>
<br>
<tt><font face=3D"Courier New"> </font></tt><br>
<br>
<br>
<br>
<tt><font face=3D"Courier =
New"> &n=
bsp;
protected void setUp() throws Exception {</font></tt><br>
<br>
<tt><font face=3D"Courier =
New"> &n=
bsp;
helper =3D new JFCTestHelper(); </font></tt><br>
<br>
<tt><font face=3D"Courier =
New">
</font></tt><br>
<br>
<tt><font face=3D"Courier =
New"> &n=
bsp; &nb=
sp;
</font></tt><br>
<br>
<tt><font face=3D"Courier =
New"> &n=
bsp;
clickme=3D(JButton)</font></tt><br>
<tt><font face=3D"Courier =
New">helper.findNamedComponent(myclass.class,"mybutton",0);
</font></tt><br>
<br>
<tt><font face=3D"Courier =
New"> &n=
bsp;
System.out.println(clickme); &nb=
sp; &nbs=
p;
</font></tt><br>
<br>
<tt><font face=3D"Courier =
New"> &n=
bsp;
System.out.println("iN setup");</font></tt><br>
<br>
<tt><font face=3D"Courier =
New"> &n=
bsp;
flushAWT(); </font></tt><br>
<br>
<tt><font face=3D"Courier =
New">
}</font></tt><br>
<br>
<br>
<br>
<tt><font face=3D"Courier New">public void testnotnull() throws =
Exception{</font></tt><br>
<tt><font face=3D"Courier =
New">
assertNotNull("Not found ",clickme);</font></tt><br>
<tt><font face=3D"Courier New">//fails </font></tt><br>
<br>
<br>
<br>
<tt><font face=3D"Courier New">}</font></tt><br>
<br>
<br>
<tt><font face=3D"Courier New">protected void tearDown() throws =
Exception{</font></tt><br>
<br>
<tt><font face=3D"Courier =
New">
super.tearDown();</font></tt><br>
<br>
<tt><font face=3D"Courier =
New">
System.out.println("In tear down");</font></tt><br>
<br>
<tt><font face=3D"Courier =
New">
}</font></tt><br>
<br>
<br>
<br>
<br>
<br>
<tt><font face=3D"Courier New">}</font></tt><br>
<br>
<br>
</span></font></p>
<p class=3DMsoNormal><font size=3D2 face=3DArial><span =
style=3D'font-size:10.0pt;
font-family:Arial'>Please help.</span></font></p>
<p class=3DMsoNormal><font size=3D2 face=3D"Book Antiqua"><span =
style=3D'font-size:
10.0pt;font-family:"Book Antiqua"'>Meera Ramachandran</span></font></p>
<p class=3DMsoNormal><font size=3D3 face=3D"Times New Roman"><span =
style=3D'font-size:
12.0pt'> </span></font></p>
</div>
</body>
</html>
------_=_NextPart_001_01C44313.81997CF9--
-------------------------------------------------------
This SF.Net email is sponsored by: Oracle 10g
Get certified on the hottest thing ever to hit the market... Oracle 10g.
Take an Oracle 10g class now, and we'll give you the exam FREE.
http://ads.osdn.com/?ad_id=3149&alloc_id=8166&op=click