Testing UI

Whenever I hear someone saying that his team is practicing automatic testing (TDD or whatever other buzzword) I find my self asking: "But how do you test the UI?". I get all sort of answers which only prove the inherent difficulties.

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.

5 comments :: Testing UI

  1. Post is very useful. Thank you, this useful information.

    Start your journey with In Software Training in Bangalore and get hands-on Experience with 100% Placement assistance from experts Trainers @eTechno Soft Solutions Located in BTM Layout Bangalore.

  2. your blog' s design is simple and clean and i like it. Your blog posts about Online writing Help are superb. Please keep them coming. Greets!

    data science training in bangalore
    data science training institute in bangalore

  3. Download Tableau Desktop for Windows PC from FileHorse. 100% Safe and Secure ✓ Free Download (32-bit/64-bit) Latest Version 2022.Tableau Desktop Free Activation Key

  4. Bulk Image Downloader Crack is an application specifically developed to help you download Full Sized images from almost any web gallery or web forum.Bulk Image Downloader Twitter

Post a Comment