GUI Testing
2 One of the practical methods commonly used to detect the presence of errors (failures) in a computer program is to exercise it by using its Graphical User Interface. Our program The output is correct? I1, I2, I3, …, In, … Expected results = ? Obtained results Inputs GUI
3 GUI Testing A GUI (Graphical User Interface) is a hierarchical, graphical front end to a software system A GUI contains graphical objects, called widgets, each with a set of properties p, which have discrete values v at run-time. At any time during the execution, the values of the properties of each widget of a GUI define the GUI state:
4 GUI-based Testing Testing GUI software systems is different from testing non-GUI software Non-GUI testing: suites are composed of test cases that invoke methods of the system and catch the return value/s; GUI-based testing: suites are composed of test cases that are: able to recognize/identify the components of a GUI; able to exercise GUI events (e.g., mouse clicks); able to provide inputs to the GUI components (e.g., filling text fields); able to test the functionality underlying a GUI set of components; able to check the GUI representations to see if they are consistent with the expected ones; often, strongly dependent on the used technology;
Example: GUI testing
6 public class calcTest { Calc obj = new public void Testtt() { JButton oneJbu = (JButton)TestUtil.GetChildComp(obj, "oneButton"); assertNotNull(oneJbu); JTextField text = (JTextField)TestUtil.GetChildComp(obj, "TextField"); assertNotNull(text); oneJbu.doClick(); assertEquals("1", text.getText()); System.out.println(text.getText()); JButton addJbu = (JButton)TestUtil.GetChildComp(obj, "addButton"); addJbu.doClick();
JButton twoJbu = (JButton)TestUtil.GetChildComp(obj, "twoButton"); assertNotNull(twoJbu); twoJbu.doClick(); assertEquals("2", text.getText()); System.out.println(text.getText()); JButton equalJbu = (JButton)TestUtil.GetChildComp(obj, "jButton14"); equalJbu.doClick(); assertEquals("3", text.getText()); System.out.println(text.getText()); }
public class TestUtil{ public static Component GetChildComp(Component parent, String name){ if (name.equals(parent.getName())) return parent; if(parent instanceof Container) { Component[] children = ((Container)parent).getComponents(); for (int i = 0; i < children.length; i++) { Component child = GetChildComp(children[i], name); if(child != null) return child; } return null; } }
Testlash natijasi
public static Component getChildComp(Component parent, String name) { if (parent instanceof Container) { Component[] children = (parent instanceof JMenu) ? ((JMenu)parent).getMenuComponents() : ((Container)parent).getComponents();