Running tests
GUI tests, by nature, are slower and more intrusive than regular unit tests. This section provides some practical advices.
Interrupting running tests
AssertJ Swing provides support for killing an already running test suite.
Simeon H. K. Fitch - inventor of this feature Let's say you're running a pretty big FEST-Swing test, one that takes a couple minutes to run. In the middle of it, a Skype call comes in. You need to answer the call, but you currently don't own the mouse! Eventually, some frantic combination of Alt, Ctrl, Cmd, Tab, Esc, F1-12, gets the window buried, and you can accept the call, but you want something more "decisive" to kill the test run.
The EmergencyAbortListener implements this feature. After registering this listener in your
test, you can terminate your test using the key combination Ctrl + Shift +
A.
private EmergencyAbortListener listener;
@BeforeMethod public void setUp() {
listener = EmergencyAbortListener.registerInToolkit();
// set up your test fixture.
}
@AfterMethod public void tearDown() {
listener.unregister();
// clean up resources.
}
The key combination can be configured too:
listener = EmergencyAbortListener.registerInToolkit()
.keyCombination(key(VK_C).modifiers(SHIFT_MASK));
Running tests without (disrupting the) desktop
AssertJ Swing tests can be executed in a Continuous Integration (CI) server. The following are tips to run and troubleshoot AssertJ Swing tests in CI servers, in different environments.
Running AssertJ Swing under a vnc server
In order to get the most value from an automated GUI testing tool like FEST-Swing [or AssertJ Swing], you'll want to have the ability to run your full suite of tests frequently. Doing so on your personal desktop can be very time consuming, as you must largely sit and watch while the tests run. If everything goes as planned, your tests will all pass and you need not have been watching it at all. If you're already running a CI (Continuous Integration) server like me (Hudson is my favorite), then the natural thing to do is run your GUI tests as part of your CI process. Even if you're not running a CI server, you would stand to benefit from not being forced t o watch your tests run every time.
If you're running Linux, BSD, or any *NIX style operating system chances are that CI server probably doesn't even have X running, so how are you to run your GUI tests?
TightVNC is the answer (or any other vnc server
you could think of). It creates a desktop that you can access via a vnc viewer locally and even
remotely. We are using TightVNC for running the tests of AssertJ Swing, too. If you're running Ubuntu
or Debian, simply sudo apt-get (or aptitude) install tightvncserver. For other distributions
(or OS) follow their normal process for installing packages.
Once installed, the process is to start the vnc server, run the tests and then kill the vnc server. Since this could be done by an ape, we're using a script to perform all these steps automatically:
This
- starts a local vnc server at display 42
- sets the
DISPLAYvariable - executes
mvn test - restores the previous
DISPLAYvalue - stops the vnc server
The script makes it easy to start an application (e.g. tests) in the background, without disrupting your desktop. If you need to access it remotely or to run multiple applications (e.g. tests), you'll have to adapt the script to your needs.
Important Why don't we just use
xvfb-run? Our tests maximize windows and do other stuff the default window manager ofxvfbdoesn't support. TightVNC makes it easy to use another window manager. Just addgnome-wm &(or the window manager of your choice) to~/.vnc/xstartupand you're ready to run.
Hopefully this simple idea will help free your desktop (and you) from spending time watching AssertJ Swing work its magic.