I'm new to JFCUnit and I'm trying to figure it out. I started with a basic test class with 2 buttons and one label. I ran a test using NamedComponentFinder looking for the button named "Cancel" and the label named "Test" and using the findAll() method and it seems to find each component twice.
I'm sure there's a logical explanation.
Code follows: First the class, then the test.
/*
* Created on Jun 29, 2005
*
*/
package javatest;
import java.awt.BorderLayout;
import javax.swing.*;
public class MyApp {
private JFrame jf;
private JButton ok;
private JButton cancel;
private JLabel test;
public MyApp(){
jf = new JFrame();
ok = new JButton("OK");
test = new JLabel("Test");
cancel = new JButton("Cancel");
test.setName("Test");
ok.setName("OK");
cancel.setName("Cancel");
jf.getContentPane().add(ok,BorderLayout.SOUTH);
jf.getContentPane().add(cancel,BorderLayout.NORTH);
jf.getContentPane().add(test,BorderLayout.CENTER);
jf.setVisible(true);
jf.pack();
}
public static void main(String[] str){
new MyApp();
}
I'm new to JFCUnit and I'm trying to figure it out. I started with a basic test class with 2 buttons and one label. I ran a test using NamedComponentFinder looking for the button named "Cancel" and the label named "Test" and using the findAll() method and it seems to find each component twice.
I'm sure there's a logical explanation.
Code follows: First the class, then the test.
/*
* Created on Jun 29, 2005
*
*/
package javatest;
import java.awt.BorderLayout;
import javax.swing.*;
public class MyApp {
private JFrame jf;
private JButton ok;
private JButton cancel;
private JLabel test;
public MyApp(){
jf = new JFrame();
ok = new JButton("OK");
test = new JLabel("Test");
cancel = new JButton("Cancel");
test.setName("Test");
ok.setName("OK");
cancel.setName("Cancel");
jf.getContentPane().add(ok,BorderLayout.SOUTH);
jf.getContentPane().add(cancel,BorderLayout.NORTH);
jf.getContentPane().add(test,BorderLayout.CENTER);
jf.setVisible(true);
jf.pack();
}
public static void main(String[] str){
new MyApp();
}
}
package javatest;
import java.awt.*;
import java.util.List;
import javax.swing.*;
import junit.extensions.jfcunit.*;
import junit.extensions.jfcunit.finder.*;
import junit.framework.TestCase;
public class MyAppTest extends JFCTestCase {
private JFCTestHelper helper;
MyApp ma = new MyApp();
public static void main(String[] args) {
junit.swingui.TestRunner.run(MyAppTest.class);
}
protected void setUp() throws Exception {
super.setUp();
helper = new JFCTestHelper();
}
protected void tearDown() throws Exception {
super.tearDown();
helper = null;
ma = null;
}
public void testMain() {
List windows;
MyApp.main(new String[0]);
awtSleep();
NamedComponentFinder buttonFinder = new NamedComponentFinder(JButton.class,"Cancel");
NamedComponentFinder labelFinder = new NamedComponentFinder(JLabel.class,"Test");
windows = buttonFinder.findAll();
System.out.println("MyAppTest.testMain>size= "+windows.size());
for (int i=0;i<windows.size();i++){
System.out.println("MyAppTest.testMain>buttons "+i+" = "+windows.get(i));
}
windows = labelFinder.findAll();
System.out.println("MyAppTest.testMain>size= "+windows.size());
for (int i=0;i<windows.size();i++){
System.out.println("MyAppTest.testMain>labels "+i+" = "+windows.get(i));
}
//TODO Implement main().
}
}
Roy