PageRenderTime 117ms CodeModel.GetById 108ms app.highlight 4ms RepoModel.GetById 0ms app.codeStats 1ms

/tests/Fest/build.xml

#
XML | 496 lines | 263 code | 72 blank | 161 comment | 0 complexity | be4a071018eb117d043957d8e822888e MD5 | raw file
  1
  2<project name="jEditTestFramework" default="compileFramework" basedir=".">
  3
  4    <description>
  5    This is the build file for the jEdit unit test framework based on Fest. This
  6    build file both builds the framework classes and runs unit tests.
  7    
  8    The only target that should be called directly in this build file is
  9    "compileFramework".  The only target that should be called indirectly is
 10    "-test", which should be called from a project build file, such as the one
 11    in jedit_tests/build.xml or from a plugin test build file.  All other
 12    targets are used as necessary from these two targets.
 13    
 14    This build file provides several main features:
 15    1. Does a clean build of jEdit from source.  
 16    2. Builds the test framework code.
 17    3. Sets up the jEdit settings directory in the directory containing this
 18    build file.  This makes sure the settings directory is clean.
 19    4. Builds the unit tests.  These may be tests for jEdit itself or for
 20    plugings.
 21    5. Copies plugin jars, if necessary, to the settings directory.
 22    6. Runs the unit tests.
 23    
 24    The specifics of the properties required to run the tests are in the
 25    comments in this build file and in the example plugin test build file.
 26    
 27    The directory structure for the test framework is:
 28    
 29    jEditTestFramework
 30    |
 31    +- build (contains the compiled classes for the test framework itself)
 32    +- jedit_settings (this is passed in the -settings parameter to jEdit)
 33    +- jedit_tests (source code for unit tests for jEdit itself)
 34    +- jedit_tests_classes (the compiled classes for the jEdit unit tests)
 35    +- lib (the jar files for the Fest unit testing framework)
 36    +- src (the source code for the jEdit test framework)
 37       |
 38       + org/gjt/sp/jedit/testframework
 39         |- AbstractButtonMatcher.java (helper to find buttons)
 40         |- FirstDialogMatcher.java (helper to find dialogs)
 41         |- Log.java (a simple logger to help debug tests)
 42         |- TestUtils.java (the main class for jEdit testing, this class 
 43                actually starts jEdit and provides a number of convenience
 44                methods to find parts of jEdit.)
 45                
 46    See build.properties.examples for possible configuration options for your 
 47    system.
 48    </description>
 49
 50
 51    <!-- load properties from a file.  This allows for overriding properties
 52    set below. -->
 53    <property file="${build.properties}"/>
 54    <property file="build.properties"/>
 55
 56    <!-- location of this test framework -->
 57    <property name="test.framework.home" location="${basedir}"/>
 58
 59    <!-- uncomment this property or set it in a calling build file to avoid 
 60    rebuilding jEdit each time -->
 61    <!--
 62    <property name="dont_-buildjEdit" value=""/>
 63    -->
 64
 65    <!-- =======================================================================
 66    Properties, these shouldn't need to change, but can be modified with the 
 67    properties files loaded above.
 68    ======================================================================== -->
 69
 70    <!-- where the jEdit source files live.  At the top level of this folder
 71    should be where the main jEdit build file lives, assumes targets "clean-all"
 72    and "build" exist in the main jEdit build file, assumes the build file will
 73    put the compiled jEdit code into a "build" directory. -->
 74    <property name="test.jedit.src" location="${test.framework.home}/../../jEdit"/>
 75    
 76    <!-- location of jEdit.jar, modes, properties, etc, defaults to the build
 77    folder in the main jEdit source directory. This build file can build a 
 78    clean install of jEdit each time tests are ran.  You can change this property
 79    if you want to use a different jEdit installation. -->
 80    <property name="test.jedit.home" location="${test.jedit.src}/build"/>
 81    
 82    <!-- the jEdit settings directory to use when running jEdit.  This defaults
 83    to the jedit_settings folder in the framework home. -->
 84    <property name="test.jedit.settings.dir" location="${test.framework.home}/jedit_settings"/>
 85
 86    <!-- plugin jar files will be copied to this directory -->
 87    <property name="test.jedit.jars" location="${test.jedit.settings.dir}/jars"/>
 88    <mkdir dir="${test.jedit.jars}"/>
 89    <property name="test.jedit.jars-cache" location="${test.jedit.settings.dir}/jars-cache"/>
 90    
 91    <!-- where the source code for the test framework lives -->
 92    <property name="test.framework.src.dir" location="${test.framework.home}/src"/>
 93
 94    <!-- where the compiled framework classes go -->
 95    <property name="test.framework.classes.dir" location="${test.framework.home}/build"/>
 96    <mkdir dir="${test.framework.classes.dir}"/>
 97    
 98    <!-- where the framework's javadoc goes -->
 99    <property name="test.framework.javadoc.dir" location="${test.framework.home}/doc"/>
100    <mkdir dir="${test.framework.javadoc.dir}"/>
101
102    <!-- the test framework includes a simple file logger which is handy when 
103    attempting to debug the framework and/or unit tests. This property specifies
104    the output file for the logger. -->
105    <property name="test.log.file" value="${user.home}/jedit_test_debug.txt"/>
106
107    <!-- JUnit options -->
108    <property name="junit.printsummary" value="on"/>
109    <property name="junit.haltonfailure" value="off"/>
110    <property name="junit.showoutput" value="on"/>
111    <property name="junit.usefile" value="off"/>
112
113    <!-- where to put tests results, these are produced by junit-->
114    <property name="test.output" value="${basedir}/test_reports" />
115    <mkdir dir="${test.output}"/>
116    
117    <!-- FEST jar files for compile and run classpath-->
118    <path id="fest.class.path">
119        <fileset dir="${test.framework.home}/lib">
120            <include name="**/*.jar"/>
121        </fileset>
122        <!-- enable emma.properties to be found -->
123        <pathelement path="${test.framework.home}/lib"/>
124        <!-- need this for fluent assertions -->
125	<pathelement location="${hamcrest.jar}" />
126	<pathelement location="${junit.jar}" />
127    </path>
128
129    <!-- framework class path, include FEST libraries, and jedit.jar -->
130    <path id="framework.class.path">
131        <path refid="fest.class.path"/>
132        <fileset dir="${test.jedit.home}">
133            <include name="jedit.jar"/>
134        </fileset>
135        <pathelement path="${test.framework.classes.dir}"/>
136    </path>
137
138    <!-- calling build files can set some system properties, these will be passed
139    to the junit task. -->
140    <propertyset id="project.test.sysproperties"/>
141
142    <!-- =======================================================================
143    Selectors for the specific tests to run.  There are two selectors, one to
144    run all the unit tests, and another to run just one test.  The single test
145    selector is useful when writing a new test.  Other selectors can be added
146    here to run tests on a specific area of jEdit.
147
148    Which selector to use is set in the junit.testcases selector.
149    
150    These are examples that can be modified and used in other build files.
151    ======================================================================== -->
152    <!-- this selector holds all test cases -->
153    <!--
154    <selector id="testcases.all">
155        <or>
156            <filename name="test/**/*Test.java"/>
157        </or>
158    </selector>
159    -->
160    
161    <!-- this selector holds just one test -->
162    <!--
163    <selector id="testcases.current">
164        <filename name="test/search/SearchAndReplaceTest.java"/>
165    </selector>
166    -->
167    
168    <!-- this selector controls which tests to run, set the refid to either
169    testcases.current to run just one test or testcases.all to run all tests. -->
170    <!--
171    <selector id="junit.testcases">
172        <or>
173            <selector refid="testcases.current"/>
174        </or>
175    </selector>
176    -->
177    
178    
179    <!-- =======================================================================
180    Target: -buildjEdit
181    Calls "clean-all" and "build" in the main jEdit build file.
182    ======================================================================== -->
183    <target name="-buildjEdit" description="Build jEdit, prerequisite for tests." unless="dont_-buildjEdit">
184    	<echo message="test.jedit.src=${test.jedit.src}"/>
185        <ant antfile="${test.jedit.src}/build.xml" dir="${test.jedit.src}" target="clean-all" inheritall="false"/>
186        <ant antfile="${test.jedit.src}/build.xml" dir="${test.jedit.src}" target="build" inheritall="false"/>
187    </target>
188
189    
190    <!-- =======================================================================
191    Target: compileFramework
192    Builds jEdit, then compiles jEdit then the framework classes.
193    ======================================================================== -->
194    <target name="compileFramework" description="Compile the test framework classes" depends="-cleanFramework, -buildjEdit">
195        <mkdir dir="${test.framework.classes.dir}" />
196        <javac srcdir="${test.framework.src.dir}" destdir="${test.framework.classes.dir}" debug="true" source="1.5" target="1.5">
197            <classpath refid="framework.class.path"/>
198        </javac>
199        <javadoc sourcepath="${test.framework.src.dir}" destdir="${test.framework.javadoc.dir}" source="1.5"
200        		use="true" windowtitle="jEdit Test Framework API">
201        	<link href="http://fest.easytesting.org/swing/apidocs/"/>
202        	<link href="http://fest.easytesting.org/assert/apidocs/"/>
203        	<link href="http://junit.sourceforge.net/javadoc/"/>
204            <classpath>
205                <pathelement location="${junit.jar}" />
206                <pathelement location="${hamcrest.jar}" />
207                <path refid="framework.class.path"/>
208            </classpath>
209        </javadoc>
210    </target>
211    
212    
213    <!-- =======================================================================
214    Target: -compileTests
215    Compiles the test classes for the project.
216    ======================================================================== -->
217    <target name="-compileTests" description="Compile the project test classes" depends="-cleanTests">
218        <available file="${project.test.src.dir}" type="dir" property="project.test.src.dir.present"/>
219        <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.">
220            <condition>
221                <not>
222                    <isset property="project.test.src.dir.present"/>
223                </not>
224            </condition>
225        </fail>
226    
227        <echo>project.test.src.dir = ${project.test.src.dir}</echo>
228        <echo>project.test.classes.dir = ${project.test.classes.dir}</echo>
229        <javac srcdir="${project.test.src.dir}" destdir="${project.test.classes.dir}" debug="true" source="1.5" target="1.5" includeantruntime="false">
230            <selector refid="projectFiles"/>
231            <classpath refid="framework.class.path"/>
232            <classpath refid="project.class.path"/>
233        </javac>
234    </target>
235
236
237    <!-- =======================================================================
238    Target: test
239    Runs all tests as specified in the junit.testcases selector.
240    ======================================================================== -->
241    <target name="-test" description="Runs the jUnit tests." depends="-prepSettingsDir, -deletePluginJars, -instrument, -compileTests, -copyResources">
242        <echo message="Running tests..."/>
243
244        <mkdir dir="${test.output}"/>
245        
246        <!-- clean old test results -->
247        <delete failonerror="false" file="${basedir}/coverage.ec"/>
248        
249        <junit printsummary="${junit.printsummary}" haltonfailure="${junit.haltonfailure}" showoutput="${junit.showoutput}" fork="yes">
250         	<!-- no matter what I try, this is ignored : always get coverage.ec in basedir
251         	     I gave up and merge it in the -report target
252         	<jvmarg value="-Demma.coverage.out.file=${test.output}/coverage.emma"/> -->
253            <sysproperty key="test-jedit.settings" path="${test.jedit.settings.dir}"/>
254            <sysproperty key="test-tests.dir" path="tests"/>
255            <sysproperty key="jedit.home" path="${test.jedit.home}"/>
256            <sysproperty key="LOG_FILE" path="${test.log.file}"/>
257            <syspropertyset refid="project.test.sysproperties"/>
258
259            <classpath>
260                <pathelement location="${junit.jar}" />
261                <pathelement location="${hamcrest.jar}" />
262                <path refid="framework.class.path"/>
263                <!-- use the instrumented jar file, not the original one !! -->
264                <path>
265                    <fileset dir="${test.jedit.settings.dir}/jars" includes="*.jar"/>
266                </path>
267                <pathelement path="${project.test.classes.dir}"/>
268            </classpath>
269
270            <batchtest todir="${test.output}">
271                <fileset dir="${project.test.src.dir}">
272                    <selector refid="junit.testcases"/>
273                </fileset>
274            </batchtest>
275            <formatter type="brief" usefile="${junit.usefile}"/>
276            <formatter type="xml" usefile="yes"/>
277        </junit>
278        <echo>after junit</echo>
279        <antcall target="-report"/>
280    </target>
281
282    <!-- =======================================================================
283    Target: pretSettingsDir
284    Creates the directory specified in the test.jedit.settings.dir property.
285    The plugin jars will be copied into the 'jars' subdirectory of this
286    directory. This target also deletes any properties file that may have
287    existed from previous test runs from this directory.
288    ======================================================================== -->
289    <target name="-prepSettingsDir">
290        <available file="${test.jedit.settings.dir}" type="dir" property="settings.dir.present"/>
291        <fail message="${test.jedit.settings.dir} does not exist, run -buildjEdit target first.">
292            <condition>
293                <not>
294                    <isset property="settings.dir.present"/>
295                </not>
296            </condition>
297        </fail>
298    
299        <!-- need to create a jEdit properties file with 'firstTime' and
300         'tip.show' both set to false to prevent the help viewer from
301         showing on a clean build and to prevent the tips dialog from
302         showing on jEdit start up. -->
303        <delete dir="${test.jedit.settings.dir}/properties"/>
304        <echo file="${test.jedit.settings.dir}/properties">
305        firstTime=false
306        tip.show=false
307        </echo>
308
309        <delete quiet="true" dir="${test.jedit.settings.dir}/DockableWindowManager"/>
310        <delete quiet="true">
311            <fileset dir="${test.jedit.settings.dir}">
312                <include name="activity.log"/>
313                <include name="perspective.xml"/>
314                <include name="server"/>
315            </fileset>
316        </delete>
317        <delete quiet="true">
318            <fileset dir="${test.jedit.settings.dir}/settings-backup">
319                <include name="**/*"/>
320            </fileset>
321        </delete>
322        <!-- I had an old settings file in plugins/XMLPlugin and got
323             unexpected behaviour until I found it...
324          -->
325        <delete quiet="true" dir="${test.jedit.settings.dir}/plugins"/>
326    </target>
327    
328    
329    <!-- =======================================================================
330    Target: -copyPluginJars 
331    Copies jars/files specified in a selector named "plugin.jars" to the 
332    designated jars directory.  Note that the property "-copyPluginJars" must
333    exist, the value of this property does not matter.
334    ======================================================================== -->
335    <target name="-copyPluginJars" depends="-deletePluginJars" if="copyPluginJars">
336        <!-- then copy the specified files into the jars directory -->
337        <copy todir="${test.jedit.jars}">
338            <filelist refid="plugin.jars"/>
339        </copy>
340    </target>
341    
342    <!-- =======================================================================
343    Target: -copyResouces
344    Copies resources specified in a selector named "project.resources".  This is
345    to allow static resources such as test data files to be copied into the 
346    classpath so they are available for tests to use.
347    ======================================================================== -->
348    <target name="-copyResources">
349        <copy todir="${project.test.classes.dir}">
350            <fileset refid="project.resources"/>
351        </copy>
352    </target>
353    
354    <!-- =======================================================================
355    Target: -deletePluginJars
356    Deletes any jars and files from the jars and jars-cache directories in the
357    test.jedit.settings.dir.
358    ======================================================================== -->
359    <target name="-deletePluginJars">
360        <delete quiet="true">
361            <fileset dir="${test.jedit.jars}">
362                <include name="**/*"/>
363            </fileset>
364        </delete>
365        <delete quiet="true">
366            <fileset dir="${test.jedit.jars-cache}">
367                <include name="**/*"/>
368            </fileset>
369        </delete>
370    </target>
371
372    
373    <!-- =======================================================================
374    Target: -cleanFramework
375    Removes compiled framework classes from the build directory.
376    ======================================================================== -->
377    <target name="-cleanFramework" description="Remove framework classes from the build directory">
378        <echo message="Removing framework classes ..."/>
379        <delete>
380            <fileset dir="${test.framework.classes.dir}">
381                <include name="**/*"/>
382            </fileset>
383        </delete>
384    </target>
385    
386    
387    <!-- =======================================================================
388    Target: -cleanTests
389    Removes compiled test classes.
390    ======================================================================== -->
391    <target name="-cleanTests" description="Remove unit tests from the project build directory">
392        <echo message="Removing test classes ..."/>
393        
394        <available file="${project.test.classes.dir}" type="dir" property="project.test.classes.dir.present"/>
395        <fail message="Classes directory for project is not defined.  This target should not be called directly.">
396            <condition>
397                <not>
398                    <isset property="project.test.classes.dir.present"/>
399                </not>
400            </condition>
401        </fail>
402    
403        <delete quiet="true">
404            <fileset dir="${project.test.classes.dir}">
405                <include name="**/*"/>
406            </fileset>
407        </delete>
408    </target>
409    
410    
411    <path id="emma.lib" >
412    	<pathelement location="${test.framework.home}/lib/emma.jar" />
413    	<pathelement location="${test.framework.home}/lib/emma_ant.jar" />
414    	<!-- for the emma.properties file -->
415    	<pathelement location="${test.framework.home}/lib" />
416    </path>
417
418    <taskdef resource="emma_ant.properties" classpathref="emma.lib" />
419    
420    <!-- directory where to find the project file to instrument.
421    	 Should only be overloaded for jedit tests.
422    	 Don't forget to set project.toinstrument.jar, however.
423      -->
424    <property name="project.toinstrument.dir" value="${test.jedit.jars}" />
425    
426    <!-- what classes to include in the code coverage. Accept all classes by default.
427    	 The filter is on class names (no .class suffix please).
428    	 You can use a specific filter, like value='xml.Resolver*', to go with
429    	 a single test case.
430      -->
431    <property name="emma.filter" value="*" />
432
433
434
435    <!-- define this property in order to get code coverage :
436         <property name="emma.enabled" value="true"/>  
437     -->   
438
439    <!-- define this property in order to get a nice html report in the end :
440         <property name="junit-report.enabled" value="true"/>  
441     -->   
442
443   <!-- =======================================================================
444    Target: -instrument
445    Instruments project classes
446    ======================================================================== -->
447    <target name="-instrument" depends="-copyPluginJars"  if="emma.enabled">
448    	
449        <!-- clean old instrumentation metadata -->
450        <delete failonerror="false" file="${basedir}/metadata.em"/>
451		
452        <emma enabled="true">
453			<instr
454				metadatafile="${basedir}/metadata.em"  
455				mode="overwrite"
456			>
457				<instrpath path="${project.toinstrument.dir}/${project.toinstrument.jar}"/>
458				<filter includes="${emma.filter}"/>
459			</instr>
460		 </emma> 
461	</target>  
462       
463    <!-- =======================================================================
464    Target: -report.emma
465    Generate an HTML report from the test cases
466    ======================================================================== -->
467     <target name="-report.emma"  if="emma.enabled">  
468        <emma>  
469         <report sourcepath="${project.src.dir}" >  
470              <fileset dir="${basedir}" >  
471                 <include name="metadata.em" />  
472                 <include name="coverage.ec" />  
473              </fileset>  
474              <html outfile="${test.output}/coverage.html" />  
475           </report>  
476        </emma>  
477     </target>  
478    
479    <!-- =======================================================================
480    Target: -report.junit
481    Generate an HTML report from the junit test case results
482    You'll have to open test_reports/index.html to see the results
483    ======================================================================== -->
484     <target name="-report.junit"  if="junit-report.enabled">  
485        <junitreport todir="${test.output}">
486	  <fileset dir="${test.output}">
487	    <include name="TEST-*.xml"/>
488	  </fileset>
489	  <report format="frames" todir="${test.output}"/>
490	</junitreport>
491     </target>  
492     
493     <target name="-report" depends="-report.junit,-report.emma">
494     </target>
495</project>
496