So today, I tried UISpec4J. It is too early for me to comment on the overall quality of this library, but the first impression is quite good. However, their documentation fails to provide the reader with a quick, fully-working example (which is the single most important piece of information that the user of a library needs). The following fragment is my attempt to fill this gap: take it, compile it, run it.
The subject program:
import java.awt.event.*;
import javax.swing.*;
public class Win extends JFrame
{
private static final long
serialVersionUID = -9206602636016215477L;
public Win()
{
JPanel panel = new JPanel();
final JButton b = new JButton("A Button");
b.setVisible(false);
JButton t = new JButton("Toggle");
t.addActionListener(new ActionListener()
{
boolean show = false;
public void actionPerformed(ActionEvent e)
{
show = !show;
b.setVisible(show);
}
});
panel.add(t);
panel.add(b);
getContentPane().add(panel);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
...and the test program:
import org.junit.Test;
import org.uispec4j.*;
import org.uispec4j.assertion.UISpecAssert;
public class Win_Test
{
static
{
UISpec4J.init();
}
@Test
public void test1() throws Exception
{
Panel panel = new Panel(new Win());
Button b = panel.getButton("A Button");
Button t = panel.getButton("Toggle");
t.click();
UISpecAssert.assertTrue(b.isVisible());
t.click();
UISpecAssert.assertFalse(b.isVisible());
t.click();
UISpecAssert.assertTrue(b.isVisible());
}
}
Comments:
- The constructor of the tested widget (class Win) should not display the widget. This will make UISpec4J angry because it runs the tested window in some private, hidden, realm.
- The test program will need both the JUnit and the UISpec4J jars to compile
- The current version supports Java 5 but not Java 6.