Non terminating java ui tests?
This might be a bit contradictory. But I need to run a "test" that basically shows a java editor/view etc. and lets the user interact with the view without starting the remaining applicati开发者_StackOverflowon.
Something like:
public static void main(String[] args) {
Display display = new Display();
final Shell shell = new Shell(display);
shell.setSize(500, 500);
shell.setLayout(new RowLayout());
shell.setText("Composite Example");
final Composite composite = new Composite(shell, SWT.NONE);
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = 4;
composite.setLayout(gridLayout);
// Here the view is shown
MyExample sdf = new MyExample(composite, SWT.NONE);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
Is there a more systematic way of doing this (eg using junit) to create these user-interacting tests that the user must start and terminate manually?
You should first consider refactoring your code into a more testable fashion. Look at the model-view-controller design pattern, see for example http://java.sun.com/blueprints/patterns/MVC-detailed.html
When done right, all actual actions should be in the model or controller class which should be easy to test with normal JUnit tests. The view will be very thin and merely create the actual graphic components. Testing that will normally not be needed.
If you still decide to go with a GUI testing i'd suggest SWTBot as Zoltán suggested. It integrates nicely with Eclipse.
I think, you need some GUI testing tool. I know its not what you wanted in the first place, but it could serve as an automated way of "pressing the GUI buttons".
I'd suggest either SWTBot or WindowTester for experimenting.
精彩评论