FEST-Swing can take a screenshot of the desktop when a JUnit GUI test fails, either when running tests using Ant or inside an IDE (e.g. Eclipse.)
To take screenshots of failed GUI tests, regardless of how they are executed, please follow these steps:
- Add the JUnit Extension to your classpath (file fest-swing-junit-{VERSION}.jar, included when you download FEST-Swing)
- Mark GUI tests (class or method level) with the annotation
org.fest.swing.annotation.GUITest
FEST-Swing's JUnit extension requires JUnit 4.3.1.
| Changes in FEST-Swing 1.2 Starting with FEST-Swing 1.2, we have added support for JUnit 4.5. Due to JUnit's limited support for extensibility, we have changed the structure of the JUnit extension:
For more details, please read Jar Files Explained. |
Running GUI tests with Ant
In order to take screenshots of failed GUI tests with Ant please follow these steps:
- Add a definition of the Ant task
festreport - Use the formatter
org.fest.swing.junit.ant.ScreenshotOnFailureResultFormatterinside thejunitAnt task - Use the Ant task
festreportinstead ofjunitreport, and specify in its classpath where the fest-swing-junit-{VERSION}.jar file is.
Example
The following is a screenshot of a JUnit HTML report:
The Ant task festreport works exactly as junitreport: it can generate HTML reports with or without frames. It has been tested with Ant 1.7 and requires Apache-Commons Codec 1.3.
Running GUI tests in an IDE
FEST-Swing also provides a custom JUnit Runner, org.fest.swing.junit.GUITestRunner, which takes screenshots of failed GUI tests. To use it, just annotate your test class with @RunWith(GUITestRunner.class). Screenshots of failed tests will be saved in the directory "failed-gui-tests" (relative to the directory where tests are executed.)
GUITestRunner has been tested with Eclipse 3.4.1. It may not work with certain versions of IntelliJ IDEA due to bug IDEA-13389.
2 Comments
Hide/Show CommentsMay 08, 2012
Matteo Castellarin
I tried to use @RunWith(GUITestRunner.class) on NetBeans 7.1.1 but it causes the test to fail before its execution.
If I do remove that line everything works properly
May 09, 2012
Matteo Castellarin
Resolved: some mistakes in the JAR import order. Here you can find a running example of FEST for NetBeans:
NetBeansFEST.zip
All basic features are included, as well as the screenshot and some test logging.
Congratulations for the nice testing framework!