GUI tests, by nature, are slower and more intrusive than regular unit tests. This section provides some practical advices.
AssertJ Swing provides support for killing an already running test suite.
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));
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.
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:
execute-on-vnc.sh mvn test
This
DISPLAY
variablemvn test
DISPLAY
valuexvfb-run
? Our tests maximize windows and do other stuff the default
window manager of xvfb
doesn't support. TightVNC makes it easy to use another window
manager. Just add gnome-wm &
(or the window manager of your choice) to
~/.vnc/xstartup
and 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.
by Uli Schrempp (written for FEST)
As we develop software with the target platform Windows, we need to run the tests on Windows platform too. So the X-Server approach does not fit. Here are two solutions:
Open the service properties dialog of the Hudson service. Select in the Log On tab Run as Local System account and check the Allow service to interact with desktop.
This works fine, but when the Hudson system needs to access some shares in the network, then the Local System account might not have the appropriate permissions.
Here is the challenge to automatically start the Hudson agent via command-line after a restart. Here's a short recipe:
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\AutoAdminLogon=1
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultUserName=testuser
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon\DefaultPassword=secret
javaws http://HUDSON_MASTER/computer/COMPUTERNAME/slave-agent.jnlp
Sometimes when there was a remote-desktop connection to this machine running Hudson in application mode, the Windows session seems to be closed and then the tests could not start the application. Solution for that is using VNC.
The following tips are the result of this thread in the mailing list. Many thanks to (in alphabetical order)
During automated builds
cmd
command use the /k
option not the /c
option - this prevents the command window from closing and orphaning
the build agent