/tests/Fest/build.xml
XML | 496 lines | 263 code | 72 blank | 161 comment | 0 complexity | be4a071018eb117d043957d8e822888e MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
- <project name="jEditTestFramework" default="compileFramework" basedir=".">
- <description>
- This is the build file for the jEdit unit test framework based on Fest. This
- build file both builds the framework classes and runs unit tests.
-
- The only target that should be called directly in this build file is
- "compileFramework". The only target that should be called indirectly is
- "-test", which should be called from a project build file, such as the one
- in jedit_tests/build.xml or from a plugin test build file. All other
- targets are used as necessary from these two targets.
-
- This build file provides several main features:
- 1. Does a clean build of jEdit from source.
- 2. Builds the test framework code.
- 3. Sets up the jEdit settings directory in the directory containing this
- build file. This makes sure the settings directory is clean.
- 4. Builds the unit tests. These may be tests for jEdit itself or for
- plugings.
- 5. Copies plugin jars, if necessary, to the settings directory.
- 6. Runs the unit tests.
-
- The specifics of the properties required to run the tests are in the
- comments in this build file and in the example plugin test build file.
-
- The directory structure for the test framework is:
-
- jEditTestFramework
- |
- +- build (contains the compiled classes for the test framework itself)
- +- jedit_settings (this is passed in the -settings parameter to jEdit)
- +- jedit_tests (source code for unit tests for jEdit itself)
- +- jedit_tests_classes (the compiled classes for the jEdit unit tests)
- +- lib (the jar files for the Fest unit testing framework)
- +- src (the source code for the jEdit test framework)
- |
- + org/gjt/sp/jedit/testframework
- |- AbstractButtonMatcher.java (helper to find buttons)
- |- FirstDialogMatcher.java (helper to find dialogs)
- |- Log.java (a simple logger to help debug tests)
- |- TestUtils.java (the main class for jEdit testing, this class
- actually starts jEdit and provides a number of convenience
- methods to find parts of jEdit.)
-
- See build.properties.examples for possible configuration options for your
- system.
- </description>
- <!-- load properties from a file. This allows for overriding properties
- set below. -->
- <property file="${build.properties}"/>
- <property file="build.properties"/>
- <!-- location of this test framework -->
- <property name="test.framework.home" location="${basedir}"/>
- <!-- uncomment this property or set it in a calling build file to avoid
- rebuilding jEdit each time -->
- <!--
- <property name="dont_-buildjEdit" value=""/>
- -->
- <!-- =======================================================================
- Properties, these shouldn't need to change, but can be modified with the
- properties files loaded above.
- ======================================================================== -->
- <!-- where the jEdit source files live. At the top level of this folder
- should be where the main jEdit build file lives, assumes targets "clean-all"
- and "build" exist in the main jEdit build file, assumes the build file will
- put the compiled jEdit code into a "build" directory. -->
- <property name="test.jedit.src" location="${test.framework.home}/../../jEdit"/>
-
- <!-- location of jEdit.jar, modes, properties, etc, defaults to the build
- folder in the main jEdit source directory. This build file can build a
- clean install of jEdit each time tests are ran. You can change this property
- if you want to use a different jEdit installation. -->
- <property name="test.jedit.home" location="${test.jedit.src}/build"/>
-
- <!-- the jEdit settings directory to use when running jEdit. This defaults
- to the jedit_settings folder in the framework home. -->
- <property name="test.jedit.settings.dir" location="${test.framework.home}/jedit_settings"/>
- <!-- plugin jar files will be copied to this directory -->
- <property name="test.jedit.jars" location="${test.jedit.settings.dir}/jars"/>
- <mkdir dir="${test.jedit.jars}"/>
- <property name="test.jedit.jars-cache" location="${test.jedit.settings.dir}/jars-cache"/>
-
- <!-- where the source code for the test framework lives -->
- <property name="test.framework.src.dir" location="${test.framework.home}/src"/>
- <!-- where the compiled framework classes go -->
- <property name="test.framework.classes.dir" location="${test.framework.home}/build"/>
- <mkdir dir="${test.framework.classes.dir}"/>
-
- <!-- where the framework's javadoc goes -->
- <property name="test.framework.javadoc.dir" location="${test.framework.home}/doc"/>
- <mkdir dir="${test.framework.javadoc.dir}"/>
- <!-- the test framework includes a simple file logger which is handy when
- attempting to debug the framework and/or unit tests. This property specifies
- the output file for the logger. -->
- <property name="test.log.file" value="${user.home}/jedit_test_debug.txt"/>
- <!-- JUnit options -->
- <property name="junit.printsummary" value="on"/>
- <property name="junit.haltonfailure" value="off"/>
- <property name="junit.showoutput" value="on"/>
- <property name="junit.usefile" value="off"/>
- <!-- where to put tests results, these are produced by junit-->
- <property name="test.output" value="${basedir}/test_reports" />
- <mkdir dir="${test.output}"/>
-
- <!-- FEST jar files for compile and run classpath-->
- <path id="fest.class.path">
- <fileset dir="${test.framework.home}/lib">
- <include name="**/*.jar"/>
- </fileset>
- <!-- enable emma.properties to be found -->
- <pathelement path="${test.framework.home}/lib"/>
- <!-- need this for fluent assertions -->
- <pathelement location="${hamcrest.jar}" />
- <pathelement location="${junit.jar}" />
- </path>
- <!-- framework class path, include FEST libraries, and jedit.jar -->
- <path id="framework.class.path">
- <path refid="fest.class.path"/>
- <fileset dir="${test.jedit.home}">
- <include name="jedit.jar"/>
- </fileset>
- <pathelement path="${test.framework.classes.dir}"/>
- </path>
- <!-- calling build files can set some system properties, these will be passed
- to the junit task. -->
- <propertyset id="project.test.sysproperties"/>
- <!-- =======================================================================
- Selectors for the specific tests to run. There are two selectors, one to
- run all the unit tests, and another to run just one test. The single test
- selector is useful when writing a new test. Other selectors can be added
- here to run tests on a specific area of jEdit.
- Which selector to use is set in the junit.testcases selector.
-
- These are examples that can be modified and used in other build files.
- ======================================================================== -->
- <!-- this selector holds all test cases -->
- <!--
- <selector id="testcases.all">
- <or>
- <filename name="test/**/*Test.java"/>
- </or>
- </selector>
- -->
-
- <!-- this selector holds just one test -->
- <!--
- <selector id="testcases.current">
- <filename name="test/search/SearchAndReplaceTest.java"/>
- </selector>
- -->
-
- <!-- this selector controls which tests to run, set the refid to either
- testcases.current to run just one test or testcases.all to run all tests. -->
- <!--
- <selector id="junit.testcases">
- <or>
- <selector refid="testcases.current"/>
- </or>
- </selector>
- -->
-
-
- <!-- =======================================================================
- Target: -buildjEdit
- Calls "clean-all" and "build" in the main jEdit build file.
- ======================================================================== -->
- <target name="-buildjEdit" description="Build jEdit, prerequisite for tests." unless="dont_-buildjEdit">
- <echo message="test.jedit.src=${test.jedit.src}"/>
- <ant antfile="${test.jedit.src}/build.xml" dir="${test.jedit.src}" target="clean-all" inheritall="false"/>
- <ant antfile="${test.jedit.src}/build.xml" dir="${test.jedit.src}" target="build" inheritall="false"/>
- </target>
-
- <!-- =======================================================================
- Target: compileFramework
- Builds jEdit, then compiles jEdit then the framework classes.
- ======================================================================== -->
- <target name="compileFramework" description="Compile the test framework classes" depends="-cleanFramework, -buildjEdit">
- <mkdir dir="${test.framework.classes.dir}" />
- <javac srcdir="${test.framework.src.dir}" destdir="${test.framework.classes.dir}" debug="true" source="1.5" target="1.5">
- <classpath refid="framework.class.path"/>
- </javac>
- <javadoc sourcepath="${test.framework.src.dir}" destdir="${test.framework.javadoc.dir}" source="1.5"
- use="true" windowtitle="jEdit Test Framework API">
- <link href="http://fest.easytesting.org/swing/apidocs/"/>
- <link href="http://fest.easytesting.org/assert/apidocs/"/>
- <link href="http://junit.sourceforge.net/javadoc/"/>
- <classpath>
- <pathelement location="${junit.jar}" />
- <pathelement location="${hamcrest.jar}" />
- <path refid="framework.class.path"/>
- </classpath>
- </javadoc>
- </target>
-
-
- <!-- =======================================================================
- Target: -compileTests
- Compiles the test classes for the project.
- ======================================================================== -->
- <target name="-compileTests" description="Compile the project test classes" depends="-cleanTests">
- <available file="${project.test.src.dir}" type="dir" property="project.test.src.dir.present"/>
- <fail message="Source code directory for project is not defined. This target should not be called directly, it should be called from the 'test' target only.">
- <condition>
- <not>
- <isset property="project.test.src.dir.present"/>
- </not>
- </condition>
- </fail>
-
- <echo>project.test.src.dir = ${project.test.src.dir}</echo>
- <echo>project.test.classes.dir = ${project.test.classes.dir}</echo>
- <javac srcdir="${project.test.src.dir}" destdir="${project.test.classes.dir}" debug="true" source="1.5" target="1.5" includeantruntime="false">
- <selector refid="projectFiles"/>
- <classpath refid="framework.class.path"/>
- <classpath refid="project.class.path"/>
- </javac>
- </target>
- <!-- =======================================================================
- Target: test
- Runs all tests as specified in the junit.testcases selector.
- ======================================================================== -->
- <target name="-test" description="Runs the jUnit tests." depends="-prepSettingsDir, -deletePluginJars, -instrument, -compileTests, -copyResources">
- <echo message="Running tests..."/>
- <mkdir dir="${test.output}"/>
-
- <!-- clean old test results -->
- <delete failonerror="false" file="${basedir}/coverage.ec"/>
-
- <junit printsummary="${junit.printsummary}" haltonfailure="${junit.haltonfailure}" showoutput="${junit.showoutput}" fork="yes">
- <!-- no matter what I try, this is ignored : always get coverage.ec in basedir
- I gave up and merge it in the -report target
- <jvmarg value="-Demma.coverage.out.file=${test.output}/coverage.emma"/> -->
- <sysproperty key="test-jedit.settings" path="${test.jedit.settings.dir}"/>
- <sysproperty key="test-tests.dir" path="tests"/>
- <sysproperty key="jedit.home" path="${test.jedit.home}"/>
- <sysproperty key="LOG_FILE" path="${test.log.file}"/>
- <syspropertyset refid="project.test.sysproperties"/>
- <classpath>
- <pathelement location="${junit.jar}" />
- <pathelement location="${hamcrest.jar}" />
- <path refid="framework.class.path"/>
- <!-- use the instrumented jar file, not the original one !! -->
- <path>
- <fileset dir="${test.jedit.settings.dir}/jars" includes="*.jar"/>
- </path>
- <pathelement path="${project.test.classes.dir}"/>
- </classpath>
- <batchtest todir="${test.output}">
- <fileset dir="${project.test.src.dir}">
- <selector refid="junit.testcases"/>
- </fileset>
- </batchtest>
- <formatter type="brief" usefile="${junit.usefile}"/>
- <formatter type="xml" usefile="yes"/>
- </junit>
- <echo>after junit</echo>
- <antcall target="-report"/>
- </target>
- <!-- =======================================================================
- Target: pretSettingsDir
- Creates the directory specified in the test.jedit.settings.dir property.
- The plugin jars will be copied into the 'jars' subdirectory of this
- directory. This target also deletes any properties file that may have
- existed from previous test runs from this directory.
- ======================================================================== -->
- <target name="-prepSettingsDir">
- <available file="${test.jedit.settings.dir}" type="dir" property="settings.dir.present"/>
- <fail message="${test.jedit.settings.dir} does not exist, run -buildjEdit target first.">
- <condition>
- <not>
- <isset property="settings.dir.present"/>
- </not>
- </condition>
- </fail>
-
- <!-- need to create a jEdit properties file with 'firstTime' and
- 'tip.show' both set to false to prevent the help viewer from
- showing on a clean build and to prevent the tips dialog from
- showing on jEdit start up. -->
- <delete dir="${test.jedit.settings.dir}/properties"/>
- <echo file="${test.jedit.settings.dir}/properties">
- firstTime=false
- tip.show=false
- </echo>
- <delete quiet="true" dir="${test.jedit.settings.dir}/DockableWindowManager"/>
- <delete quiet="true">
- <fileset dir="${test.jedit.settings.dir}">
- <include name="activity.log"/>
- <include name="perspective.xml"/>
- <include name="server"/>
- </fileset>
- </delete>
- <delete quiet="true">
- <fileset dir="${test.jedit.settings.dir}/settings-backup">
- <include name="**/*"/>
- </fileset>
- </delete>
- <!-- I had an old settings file in plugins/XMLPlugin and got
- unexpected behaviour until I found it...
- -->
- <delete quiet="true" dir="${test.jedit.settings.dir}/plugins"/>
- </target>
-
-
- <!-- =======================================================================
- Target: -copyPluginJars
- Copies jars/files specified in a selector named "plugin.jars" to the
- designated jars directory. Note that the property "-copyPluginJars" must
- exist, the value of this property does not matter.
- ======================================================================== -->
- <target name="-copyPluginJars" depends="-deletePluginJars" if="copyPluginJars">
- <!-- then copy the specified files into the jars directory -->
- <copy todir="${test.jedit.jars}">
- <filelist refid="plugin.jars"/>
- </copy>
- </target>
-
- <!-- =======================================================================
- Target: -copyResouces
- Copies resources specified in a selector named "project.resources". This is
- to allow static resources such as test data files to be copied into the
- classpath so they are available for tests to use.
- ======================================================================== -->
- <target name="-copyResources">
- <copy todir="${project.test.classes.dir}">
- <fileset refid="project.resources"/>
- </copy>
- </target>
-
- <!-- =======================================================================
- Target: -deletePluginJars
- Deletes any jars and files from the jars and jars-cache directories in the
- test.jedit.settings.dir.
- ======================================================================== -->
- <target name="-deletePluginJars">
- <delete quiet="true">
- <fileset dir="${test.jedit.jars}">
- <include name="**/*"/>
- </fileset>
- </delete>
- <delete quiet="true">
- <fileset dir="${test.jedit.jars-cache}">
- <include name="**/*"/>
- </fileset>
- </delete>
- </target>
-
- <!-- =======================================================================
- Target: -cleanFramework
- Removes compiled framework classes from the build directory.
- ======================================================================== -->
- <target name="-cleanFramework" description="Remove framework classes from the build directory">
- <echo message="Removing framework classes ..."/>
- <delete>
- <fileset dir="${test.framework.classes.dir}">
- <include name="**/*"/>
- </fileset>
- </delete>
- </target>
-
-
- <!-- =======================================================================
- Target: -cleanTests
- Removes compiled test classes.
- ======================================================================== -->
- <target name="-cleanTests" description="Remove unit tests from the project build directory">
- <echo message="Removing test classes ..."/>
-
- <available file="${project.test.classes.dir}" type="dir" property="project.test.classes.dir.present"/>
- <fail message="Classes directory for project is not defined. This target should not be called directly.">
- <condition>
- <not>
- <isset property="project.test.classes.dir.present"/>
- </not>
- </condition>
- </fail>
-
- <delete quiet="true">
- <fileset dir="${project.test.classes.dir}">
- <include name="**/*"/>
- </fileset>
- </delete>
- </target>
-
-
- <path id="emma.lib" >
- <pathelement location="${test.framework.home}/lib/emma.jar" />
- <pathelement location="${test.framework.home}/lib/emma_ant.jar" />
- <!-- for the emma.properties file -->
- <pathelement location="${test.framework.home}/lib" />
- </path>
- <taskdef resource="emma_ant.properties" classpathref="emma.lib" />
-
- <!-- directory where to find the project file to instrument.
- Should only be overloaded for jedit tests.
- Don't forget to set project.toinstrument.jar, however.
- -->
- <property name="project.toinstrument.dir" value="${test.jedit.jars}" />
-
- <!-- what classes to include in the code coverage. Accept all classes by default.
- The filter is on class names (no .class suffix please).
- You can use a specific filter, like value='xml.Resolver*', to go with
- a single test case.
- -->
- <property name="emma.filter" value="*" />
- <!-- define this property in order to get code coverage :
- <property name="emma.enabled" value="true"/>
- -->
- <!-- define this property in order to get a nice html report in the end :
- <property name="junit-report.enabled" value="true"/>
- -->
- <!-- =======================================================================
- Target: -instrument
- Instruments project classes
- ======================================================================== -->
- <target name="-instrument" depends="-copyPluginJars" if="emma.enabled">
-
- <!-- clean old instrumentation metadata -->
- <delete failonerror="false" file="${basedir}/metadata.em"/>
-
- <emma enabled="true">
- <instr
- metadatafile="${basedir}/metadata.em"
- mode="overwrite"
- >
- <instrpath path="${project.toinstrument.dir}/${project.toinstrument.jar}"/>
- <filter includes="${emma.filter}"/>
- </instr>
- </emma>
- </target>
-
- <!-- =======================================================================
- Target: -report.emma
- Generate an HTML report from the test cases
- ======================================================================== -->
- <target name="-report.emma" if="emma.enabled">
- <emma>
- <report sourcepath="${project.src.dir}" >
- <fileset dir="${basedir}" >
- <include name="metadata.em" />
- <include name="coverage.ec" />
- </fileset>
- <html outfile="${test.output}/coverage.html" />
- </report>
- </emma>
- </target>
-
- <!-- =======================================================================
- Target: -report.junit
- Generate an HTML report from the junit test case results
- You'll have to open test_reports/index.html to see the results
- ======================================================================== -->
- <target name="-report.junit" if="junit-report.enabled">
- <junitreport todir="${test.output}">
- <fileset dir="${test.output}">
- <include name="TEST-*.xml"/>
- </fileset>
- <report format="frames" todir="${test.output}"/>
- </junitreport>
- </target>
-
- <target name="-report" depends="-report.junit,-report.emma">
- </target>
- </project>