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:
org.fest.swing.annotation.GUITestFEST-Swing's JUnit extension requires JUnit 4.3.1.
|
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. |
In order to take screenshots of failed GUI tests with Ant please follow these steps:
festreportorg.fest.swing.junit.ant.ScreenshotOnFailureResultFormatter inside the junit Ant taskfestreport instead of junitreport, and specify in its classpath where the fest-swing-junit-{VERSION}.jar file is.
<target name="test" depends="compile">
<taskdef resource="festjunittasks" classpathref="lib.classpath" />
<junit forkmode="perBatch" printsummary="yes" haltonfailure="no" haltonerror="no">
<classpath refid="lib.classpath" />
<classpath location="${target.test.classes.dir}" />
<classpath location="${target.classes.dir}" />
<formatter classname="org.fest.swing.junit.ant.ScreenshotOnFailureResultFormatter" extension=".xml" />
<batchtest fork="yes" todir="${target.junit.results.dir}">
<fileset dir="${target.test.classes.dir}" includes="**/*Test*.class" />
</batchtest>
</junit>
<festreport todir="${target.junit.report.dir}">
<classpath refid="lib.classpath" />
<fileset dir="${target.junit.results.dir}">
<include name="TEST-*.xml" />
</fileset>
<report format="frames" todir="${target.junit.report.dir}/html" />
</festreport>
</target>
|
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.
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.