Package org.fest.swing.fixture
The power and flexibility of FEST-Swing come from the fixtures in
this package. Although you can use the
directly, it is too
low-level and requires, in our opinion, too much code. FEST fixtures can simplify creation and maintenance of functional
GUI tests by:
BasicRobot
- providing reliable lookup of GUI components (by component name or using custom criteria)
- simulating user events on GUI components
- providing assertion methods about the state of GUI components
The following example shows how easy is to use FEST fixtures. The test verifies that an error message is displayed if the user enters her username but forgets to enter her password.
private FrameFixture
window;
@BeforeMethod public void setUp() {
window = new FrameFixture(new LoginWindow());
window.show();
}
@AfterMethod public void tearDown() {
window.cleanUp();
}
@Test public void shouldCopyTextInLabelWhenClickingButton() {
window.textBox("username").enterText("some.user");
window.button("login").click();
window.optionPane().requireErrorMessage().requireMessage("Please enter your password");
}
The test uses a
to launch the GUI to test
(FrameFixture
LoginWindow
) and find the GUI components in such window. This is the recommended way to use FEST. We
could also use individual fixtures to simulate user events, but it would result in more code to write and maintain:
private BasicRobot
robot;
@BeforeMethod public void setUp() {
robot = BasicRobot.robotWithNewAwtHierarchy();
robot.showWindow(new LoginWindow());
}
@AfterMethod public void tearDown() {
robot.cleanUp();
}
@Test public void shouldCopyTextInLabelWhenClickingButton() {
new JTextComponentFixture
(robot, "username").enterText("some.user");
new JButtonFixture
(robot, "login").click();
new JOptionPaneFixture
(robot).requireErrorMessage().requireMessage("Please enter your password");
}
Note: It is very important to clean up resources used by FEST (keyboard, mouse and opened windows) after
each test; otherwise, the FEST robot will keep control of them and can make your computer pretty much unusable. To clean
up resources call the method 'cleanUp' from
,
BasicRobot
or FrameFixture
.
DialogFixture
Each fixture has the name of the GUI component it can control plus the word "Fixture" at the end. For example,
can simulate user events on
JButtonFixture
s.
JButton
-
ClassDescriptionUnderstands retrieval of client properties from GUI components.Understands state verification of
s.Color
Understands simulation of keyboard focus simulation of keyboard input simulation of mouse input state verification of a GUI component.ComponentFixture<T extends Component>Understands functional testing of
s: user input simulation state verification property value queryComponent
Understands an "extension method" for implementations of
.ContainerFixture
Understands a validator of common objects used in component fixtures.ContainerFixture<T extends Container>Understands utility methods related to
s.Container
Understands functional testing of
s: user input simulation state verification property value queryDialog
Understands state verification of an editable GUI component.Understands simulation of input focus on a GUI component.Understands state verification of
s.Font
Understands functional testing of
s: user input simulation state verification property value queryFrame
Understands functional testing of frame-like components (not necessarily subclasses of
): user input simulation state verification property value queryFrame
GenericComponentFixture<T extends Component>A generic component fixture providing basic keyboard and mouse input operations.Understands functional testing of GUI component items (e.g.Understands functional testing of
s: user input simulation state verification property value queryJButton
Understands functional testing of
es: user input simulation state verification property value queryJCheckBox
Understands functional testing of
es: user input simulation state verification property value queryJComboBox
Understands functional testing of
s: user input simulation state verification property value queryJComponent
Understands functional testing of
s: user input simulation state verification property value queryJFileChooser
Understands functional testing of
s: user input simulation state verification property value queryJInternalFrame
Understands functional testing of
s: user input simulation state verification property value queryJLabel
Understands functional testing of
s: user input simulation state verification property value queryJList
Understands functional testing of single rows in
s: user input simulation state verification property value queryJList
Understands lookup of
s.JMenuItem
Understands functional testing of
s: user input simulation state verification property value queryJMenuItem
Understands functional testing of
s: user input simulation state verification property value queryJOptionPane
Understands functional testing of
s: user input simulation state verification property value queryJPanel
Understands functional testing of
s: user input simulation state verification property value queryJPopupMenu
Understands input simulation on
s capable of invokingComponent
s.JPopupMenu
Understands functional testing of
s: state verification property value queryJProgressBar
Understands functional testing of
s: user input simulation state verification property value queryJRadioButton
Understands functional testing of
s: user input simulation state verification property value queryJScrollBar
Understands functional testing of
s: user input simulation state verification property value queryJScrollPane
Understands functional testing of
s: user input simulation state verification property value queryJSlider
Understands functional testing of
s: user input simulation state verification property value queryJSpinner
Understands functional testing of
s: user input simulation state verification property value queryJSplitPane
Understands functional testing of
s: user input simulation state verification property value queryJTabbedPane
Understands functional testing of single cells in
s: user input simulation state verification property value queryJTable
Understands functional testing of
s: user input simulation state verification property value queryJTable
Understands functional testing of
s: user input simulation state verification property value queryJTableHeader
Understands functional testing of
s: user input simulation state verification property value queryJTextComponent
Understands functional testing of
s: user input simulation state verification property value queryJToggleButton
Understands functional testing of
s: user input simulation state verification property value queryJToolBar
Understands constraints used to unfloat a floating
.JToolBar
Understands functional testing of
s: user input simulation state verification property value queryJTree
Understands functional testing of single nodes in
s: user input simulation state verification property value queryJTree
Understands functional testing of single nodes, referenced by their paths, in
s: user input simulation state verification property value queryJTree
Understands functional testing of single nodes, referenced by their row indices, in
s: user input simulation state verification property value queryJTree
Understands simulation of keyboard input on a GUI component.Understands simulation of mouse input on a GUI component.Understands state verification of a GUI component.Understands state verification and property value queries of GUI components that display text.Understands simulation of user events on GUI components that accept text input from the user.Understands state verification of GUI components that display a tool-tip.Understands state verification of "two-state" buttons.WindowFixture<T extends Window>Understands functional testing of
s: user input simulation state verification property value queryWindow
Understands functional testing of window-like containers (not necessarily subclasses of
): user input simulation state verification property value queryWindow