PageRenderTime 39ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

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