public abstract class Fixture
extends java.lang.Object
A fixture is a standalone application intended for testing one particular GUI component in isolation. Using fixtures makes it easy to write "human tests" for GUI components: you can create multiple instances of a component that represent a wide range of possible states, and then quickly inspect the fixture after making any changes to make sure that the component still renders correctly in all valid configurations.
The Fixture
class provides a boilerplate wrapper for creating fixtures easily.
The goal of the Fixture
class
is to make it so easy to write fixtures
that you write lots of them.
To create a fixture, create a concrete implementation of this class
by implementing the setUp(JFrame)
method.
Then, just add a main
method that simply invokes runMain()
:
public class MyFixture extends Fixture {
@Override
protected void setUp(JFrame frame) {
frame.add(new MyComponent()); // etc.
}
public static void main(String[] args) {
new MyFixture().runMain();
}
}
Optionally, the class may be annotated with a Fixture.Title
annotation,
which overrides the frame title for the fixture;
by default, a reasonable title will be chosen based on the implementing class name.
Modifier and Type | Class and Description |
---|---|
static interface |
Fixture.Title
Indicates the desired frame title for a
Fixture . |
Constructor and Description |
---|
Fixture() |
Modifier and Type | Method and Description |
---|---|
void |
runMain()
Create, populate, and display a frame using this
Fixture . |
protected abstract void |
setUp(javax.swing.JFrame frame)
Configure the provided frame to set up the fixture.
|
public void runMain()
Fixture
.
This is intended to be the sole method call in a main
method.protected abstract void setUp(javax.swing.JFrame frame)
Configure the provided frame to set up the fixture.
A subclass of Fixture
should override this method
to add components to the frame as desired by the fixture,
but does not need to perform any other operations on the frame,
such as pack
ing it or setting the default close operation.
These are handled automatically by runMain()
.
If this method does not change the size of the frame,
it will be pack
ed automatically.
Otherwise, the size set by this method will be respected.
frame
- the frame to configure