carbidecpp22devenv/plugins/org.eclipse.test_3.2.0/testframework.html
author cawthron
Fri, 04 Dec 2009 11:50:11 -0600
changeset 637 0c11af94aac6
permissions -rw-r--r--
add files for RCL_2_2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
637
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
     1
<html>
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
     2
<head>
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
     3
<title>Eclipse Testing Instructions</title>
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
     4
</head>
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
     5
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
     6
<body>
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
     7
<h1>The Eclipse Test Framework</h1><p>Last Modified: June 13, 2007</p><p><font size="+1"><br>
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
     8
  Introduction</font></p><p>The testing framework is comprised of the org.eclipse.test plugin and the org.eclipse.ant.optional.junit 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
     9
  fragment. </p><p>These two projects are available from the dev.eclipse.org repository and are 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    10
  included in the 	eclipse-test-framework-&lt;buildId&gt;.zip from the eclipse.org 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    11
  downloads page.</p><p><font size="+1">Building and Installation</font></p><p>Since the org.eclipse.test plugin is stored in the repository in source-code 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    12
  form, it needs to be compiled before it can be used. The org.eclipse.ant.optional.junit 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    13
  fragment does not contain any source and can be used as is from the repository.</p><ol>
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    14
  <li>Turn of automatic builds. Window->Preferences->Workbench and uncheck "Perform 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    15
    build automatically on resource modification"</li><li>Load org.eclipse.test into your workspace.</li><li>Right-click on the org.eclipse.test project in either the Navigator or Packages 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    16
    view. Select 'Rebuild Project' from the context menu. This will compile the 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    17
    entire org.eclipse.test plugin.</li><li>Finally, copy the org.eclipse.test plugin into your target Eclipse.</li>
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    18
    <li>The org.eclipse.ant.optional.junit fragment only needs to be present in 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    19
    the environment of the Eclipse that is overseeing the test process. If you 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    20
    are running the test script from within the Workbench, this means that the 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    21
    fragments need to be present withinn your development Eclipse. If you are 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    22
    running the tests from the command line, then the fragments will need to be 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    23
    present in your target Eclipse.</li></ol>
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    24
 <p><font size="+1">Setup</font></p>
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    25
 <p>Follow the steps given above to build and install all of the neccessary plugins 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    26
  and fragments. Please note that the current version of the test framework is 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    27
  not compatible with the PDE notion of self-hosting. If you want to run the tests, 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    28
  you will need to setup a full target Eclipse so that the testing framework can 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    29
  detect everything that is needed.</p>
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    30
<p>If you are writing tests for one or more Eclipse plugins, then you should
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    31
create a separate plugin for tests. The test plugin will contain all of the
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    32
tests that will be run on your development plugins, as well as defining how
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    33
those tests get run.</p>
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    34
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    35
<p>If you are not writing tests for an Eclipse plugin, then you should look into 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    36
  using JUnit on its own to test your work. JUnit is designed for testing Java 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    37
  code, and by default has no knowledge of Eclipse. There are separate mechanisms 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    38
  for using JUnit on Java code in Eclipse. See the documentation provided here:</p>
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    39
<p> <a href="http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/jdt-ui-home/plugins/org.eclipse.jdt.junit/index.html">
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    40
JUnit Support in Eclipse</a><br>
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    41
  	<a href="http://dev.eclipse.org:8080/help/content/help:/org.eclipse.jdt.doc.user/tasks/tasks-207.htm?resultof=%6a%75%6e%69%74%20&toc=%2Forg.eclipse.jdt.doc.user%2Ftoc.xml">
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    42
  	Using JUnit</a></p>
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    43
  	
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    44
  	<p>Once a test plugin has been created, you must then create an Ant script that 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    45
  will run all of the tests. Create a file called 'test.xml' in the root of your plug-in or bundle.
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    46
  This is an Ant file that defines how each test is going to be run. The 'test.xml' 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    47
  file is like a DOS batch file that scripts the entire testing process. Typically, 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    48
  the 'test.xml' file will contain targets for setting up the test run, executing 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    49
  the tests, cleaning up afterwards, and running the entire process.</p>
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    50
  
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    51
  <p><font size="+1">Converting existing Test Suites</font></p>
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    52
  
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    53
  <p>If you are converting an existing set of tests to use the new framework, the
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    54
actual tests that have been written should not need much change.</p>
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    55
  <p>If you have tests in multiple plugins, move these to a single test plug-in for your component.</p>
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    56
  
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    57
  <p>Make sure that the tests are defined in a plug-in. This is probably the most 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    58
  common cause of confusion in the entire test process. Your tests need to be 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    59
  in a plug-in so that Eclipse can find them when it tries to load them.</p>
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    60
  
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    61
  <p><font size="+1">Creating new Test Suites</font></p>
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    62
  
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    63
  <p>Creating new JUnit tests for an Eclipse plugin should be no more difficult 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    64
  than writing standard JUnit tests. Since the framework allows tests to be run 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    65
  inside of a working Eclipse, any tests that you write have available to them 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    66
  any of the methods supplied by the Eclipse platform, provided that you add the 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    67
  appropriate dependencies to your tests' manifest.</p>
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    68
  
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    69
  <p><font size="+1">Performance Issues</font></p>
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    70
  <p>You should keep in mind the number of times that Eclipse needs to be
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    71
started. Launching Eclipse has a substantial cost in terms of runtime. To
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    72
minimize the number of times the platform is started, you should consider
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    73
writing a TestSuite called AllTests for each of your test plugins. AllTests
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    74
should invoke each of the tests that you want to run for a particular plugin.
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    75
The 'test.xml' file can then run the AllTests class, which will run all of your
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    76
tests, but the platform will only ever be started once for each of your test
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    77
plugins.</p><p>Note: Sometimes tests involve shutting down, restarting, and testing the state 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    78
  of metadata that was written to disk. These session tests will require Eclipse 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    79
  to be launched several times in sequence, which will increase the runtime of 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    80
  your tests. This cannot be avoided.</p><p>&nbsp;</p>
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    81
  
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    82
  <p><font size="+1">Running the Test Suite from the UI</font></p><p>Right click on the test.xml file and select 'Run Ant...' from the pull-down 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    83
  menu. The Running Ant dialog box pops up. From the list of targets, select the 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    84
  one that runs all of your tests. If you are using the example file provided 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    85
  below, this target is called 'Run', and will be selected by default. Hit the 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    86
  'Finish' button to start the test process.</p>
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    87
  
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    88
  <p><font size="+1">Running the Test Suite from the command line</font></p>
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    89
  <p>When the test suites are invoked automatically, they are run from command
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    90
line. From the ${eclipse-home} directory, the command to use is:</p>
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    91
<code>java -jar plugins\org.eclipse.equinox.launcher_&lt;version&gt;.jar -application org.eclipse.ant.core.antRunner -buildfile ${test-plugin-path}\test.xml
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    92
-Declipse-home=${eclipse-home} -Dos=&lt;operating system&gt; -Dws=&lt;windowing system&gt; -Darch=&lt;architecture&gt;</code>
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    93
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    94
<p>Individual tests can also be invoked directly. From the ${eclipse-home}
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    95
directory, use the command:</p><code>java -jar plugins\org.eclipse.equinox.launcher_&lt;version&gt;.jar
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    96
 -application ${launcher} -os &lt;operating system&gt; -ws &lt;windowing system&gt; -arch &lt;architecture&gt; -dev bin -testpluginname ${plugin-name} 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    97
-classname ${test-classname} formattter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,&lt;path to output file with .xml extension&gt;</code> 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    98
<p>where ${launcher} is one of: <i>org.eclipse.test.uitestapplication</i> or <i>org.eclipse.test.coretestapplication</i> 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
    99
  depending on whether or not you want to run your tests within an active Workbench.</p><p><font size="+1">Output</font></p><p>By default, output from each test run is logged as XML. For each test that 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   100
  is run, the output is logged into the file called ${classname}.xml. The individual 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   101
  XML files are located in the ${eclipse-home} directory. When the test run is 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   102
  finished, you can call the <b>&quot;collect&quot;</b> target in the library 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   103
  file, which will collect the XML into a single file. See below for an example 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   104
  of how to use this target correctly.</p>
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   105
  
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   106
<h3>Other issues</h3><h4>Headless Testing vs. UI testing</h4><p>Many plugin tests will not need the Workbench active in order to run. Indeed, 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   107
  only the minimum number of plugins needed to run the plugin being tested need 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   108
  to be present when testing in a target Eclipse. There are two different Ant 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   109
  targets provided for running Eclipse plugin tests. One target starts the entire 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   110
  Workbench. The other starts Eclipse with the minimum number of plugins needed. 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   111
  It is up to you to decide which target is most appropriate. For examples, look 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   112
  at the <b>&quot;ui-test&quot;</b> and <b>&quot;core-test&quot;</b> targets below.</p>
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   113
  
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   114
<h4>Disposing the Display</h4><p>Some low-level tests for the Eclipse platform take actions that are not
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   115
normally possible inside of Eclipse. An example of this behaviour would be
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   116
disposing the display. While this action can be performed while running the UI,
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   117
it will also kill the UI for the copy of Eclipse that is running, and cause
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   118
errors when the Workbench tries to shutdown. If you need to test disposing the
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   119
display, or other similar actions, your tests should be running without a UI. </p>
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   120
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   121
<h4>Tests that are not plugins</h4><p>It is very easy to forget to define your tests inside of a plugin. If your 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   122
  tests will not load properly, make sure that a plug-in manifest exists in your 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   123
  test project, and also that the plugin is being loaded by the platform. Make 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   124
  sure that all of the dependencies are satisfied for your test plugin.</p>
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   125
  
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   126
<p><font size="+1">Interface</font></p><p>The org.eclipse.test plugin defines many useful Ant tasks/targets to aid developers 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   127
  in writing their test.xml scripts. Currently, there is only Ant targets defined, 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   128
  which can be called using Ant's built-in &lt;ant&gt; task. To use these targets, 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   129
  add the following line to the top of your script, and reference the ${library-file} 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   130
  property when calling &lt;ant&gt;:</p><code>&lt;property name=&quot;library-file&quot;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   131
value=&quot;${eclipse-home}/fragments/org.eclipse.test/library.xml&quot;/&gt; </code>
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   132
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   133
<p>The targets that are defined are: </p><ul>
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   134
  <li><b>ui-test</b> - This target runs a JUnit test suite inside of an Eclipse 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   135
    Workbench. This target is mainly for testing plugins that use the Eclipse 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   136
    UI and JFace. The output of the test pass is automatically logged in an XML 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   137
    file called ${classname}.xml. It takes four arguments: </li><ul>
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   138
  <li><i>data-dir</i> - The
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   139
      data directory of the Eclipse that gets run</li><li><i>plugin-name</i> -
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   140
      The name of the plugin that the test suite is defined in</li><li><i>classname</i> -
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   141
      The name of the class that the test suite is defined in</li><li><i>vmargs</i> - An
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   142
      optional argument string to pass to the VM running the tests</li></ul><p>For example, the following code will run the test
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   143
org.eclipse.foo.bar.MyTest in the plugin org.eclipse.foo in a new Eclipse
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   144
workbench. It passes the string &quot;-Dbaz=true&quot; to the VM. The Eclipse
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   145
stores its metadata in the directory &quot;data-folder&quot;. 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   146
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   147
<code><pre>
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   148
&lt;ant target=&quot;ui-test&quot; antfile=&quot;${library-file}&quot; dir=&quot;${eclipse-home}&quot;&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   149
  &lt;property name=&quot;data-dir&quot; value=&quot;data-folder&quot;/&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   150
  &lt;property name=&quot;plugin-name&quot; value=&quot;org.eclipse.foo&quot;/&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   151
  &lt;property name=&quot;classname&quot; value=&quot;org.eclipse.foo.bar.MyTest&quot;/&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   152
  &lt;property name=&quot;vmargs&quot; value=&quot;-Dbaz=true&quot;/&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   153
&lt;/ant&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   154
</pre></code>
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   155
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   156
  <li><b>core-test</b> - This target runs a JUnit test suite inside of an IPlatformRunnable. 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   157
    This target is for testing plugins that use the Eclipse platform, but do not 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   158
    require a UI to be running. The output of the test pass is automatically logged 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   159
    in an XML file called ${classname}.xml. It takes four arguments: </li><ul>
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   160
  <li><i>data-dir</i> - The
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   161
      data directory of the Eclipse that gets run</li><li><i>plugin-name</i> -
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   162
      The name of the plugin that the test suite is defined in</li><li><i>classname</i> -
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   163
      The name of the class that the test suite is defined in</li><li><i>vmargs</i> - An
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   164
      optional argument string to pass to the VM running the tests</li></ul><p>For example, the following code will run the test
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   165
org.eclipse.foo.bar.MyTest in the plugin org.eclipse.foo in a headless Eclipse.
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   166
It passes the string &quot;-Dbaz=true&quot; to the VM. The Eclipse stores its
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   167
metadata in the directory &quot;data-folder&quot;.
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   168
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   169
<code><pre>
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   170
&lt;ant target=&quot;core-test&quot; antfile=&quot;${library-file}&quot; dir=&quot;${eclipse-home}&quot;&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   171
  &lt;property name=&quot;data-dir&quot; value=&quot;data-folder&quot;/&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   172
  &lt;property name=&quot;plugin-name&quot; value=&quot;org.eclipse.foo&quot;/&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   173
  &lt;property name=&quot;classname&quot; value=&quot;org.eclipse.foo.bar.MyTest&quot;/&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   174
  &lt;property name=&quot;vmargs&quot; value=&quot;-Dbaz=true&quot;/&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   175
&lt;/ant&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   176
</pre></code>
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   177
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   178
 <li><b>collect</b> - This
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   179
     target collects the XML files that are produced over the course of the
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   180
     test script. It takes two arguments: </li><ul>
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   181
  <li><i>includes</i> - A
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   182
      pattern matching all XML files to be included in the test report. This
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   183
      argument is typically &quot;org*.xml&quot;</li><li><i>output-file</i> -
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   184
      The filename where the output of the test gets stored. For the automated
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   185
      build process, this file should be ${pluginname}.xml, and be located in
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   186
      the ECLIPSE_HOME directory.</li></ul><p>For example, the following code collects all of the files
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   187
matching the pattern &quot;org*.xml&quot; in the directory ${eclipse-home},
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   188
into the file named &quot;logfile.xml&quot;.
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   189
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   190
<code><pre>
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   191
&lt;ant target=&quot;collect&quot; antfile=&quot;${library-file}&quot; dir=&quot;${eclipse-home}&quot;&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   192
  &lt;property name=&quot;includes&quot; value=&quot;org*.xml&quot;/&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   193
  &lt;property name=&quot;output-file&quot; value=&quot;logfile.xml&quot;/&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   194
&lt;/ant&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   195
</pre></code>
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   196
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   197
 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   198
</ul><h2>Examples:</h2><p>Included is the 'test.xml' file from the org.eclipse.jdt.ui.tests.refactoring plugin. This
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   199
file controls all of the automated testing that is done for the  org.eclipse.jdt.ui.tests.refactoring
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   200
plugin. It can be run from inside of Eclipse or from the command line. It is
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   201
intended to serve as a template file for testing any other plugin.</p><p>Notice that the structure of the file roughly mirrors that of a JUnit test.
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   202
Targets are defined for setting up the tests, defining what needs to be done,
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   203
cleaning up after the tests, and running everything in the right order.</p>
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   204
<code><pre>
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   205
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   206
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   207
&lt;project name="testsuite" default="run" basedir="."&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   208
	&lt;!-- The property ${eclipse-home} should be passed into this script --&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   209
	&lt;!-- Set a meaningful default value for when it is not. --&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   210
	&lt;property name="eclipse-home" value="${basedir}\..\.."/&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   211
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   212
	&lt;!-- sets the properties eclipse-home, and library-file --&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   213
	&lt;property name="plugin-name" value="org.eclipse.jdt.ui.tests.refactoring"/&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   214
	&lt;property name="library-file"
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   215
            value="${eclipse-home}/plugins/org.eclipse.test/library.xml"/&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   216
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   217
	&lt;!-- This target holds all initialization code that needs to be done for --&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   218
	&lt;!-- all tests that are to be run. Initialization for individual tests --&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   219
	&lt;!-- should be done within the body of the suite target. --&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   220
	&lt;target name="init"&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   221
		&lt;tstamp/&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   222
		&lt;delete&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   223
			&lt;fileset dir="${eclipse-home}" includes="org*.xml"/&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   224
		&lt;/delete&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   225
	&lt;/target&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   226
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   227
	&lt;!-- This target defines the tests that need to be run. --&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   228
	&lt;target name="suite"&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   229
		&lt;property name="refactoring-folder" 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   230
              value="${eclipse-home}/refactoring_folder"/&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   231
		&lt;delete dir="${refactoring-folder}" quiet="true"/&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   232
		&lt;ant target="ui-test" antfile="${library-file}" dir="${eclipse-home}"&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   233
			&lt;property name="data-dir" value="${refactoring-folder}"/&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   234
			&lt;property name="plugin-name" value="${plugin-name}"/&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   235
			&lt;property name="classname" 
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   236
                value="org.eclipse.jdt.ui.tests.refactoring.all.AllAllRefactoringTests"/&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   237
		&lt;/ant&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   238
	&lt;/target&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   239
	
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   240
	&lt;!-- This target holds code to cleanup the testing environment after --&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   241
	&lt;!-- after all of the tests have been run. You can use this target to --&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   242
	&lt;!-- delete temporary files that have been created. --&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   243
	&lt;target name="cleanup"&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   244
	&lt;/target&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   245
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   246
	&lt;!-- This target runs the test suite. Any actions that need to happen --&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   247
	&lt;!-- after all the tests have been run should go here. --&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   248
	&lt;target name="run" depends="init,suite,cleanup"&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   249
		&lt;ant target="collect" antfile="${library-file}" dir="${eclipse-home}"&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   250
			&lt;property name="includes" value="org*.xml"/&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   251
			&lt;property name="output-file" value="${plugin-name}.xml"/&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   252
		&lt;/ant&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   253
	&lt;/target&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   254
	&lt;/project&gt;
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   255
</pre></code>
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   256
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   257
<h2>Known Issues:</h2><h4>Problem 1: Issues with Ant 1.3</h4><p>Ant 1.3 has some issues when used with the &lt;style&gt; tag and absolute
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   258
paths. Also, any tests that use the <code>System.exit()</code> call will not
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   259
log their output properly when using Ant 1.3.</p><h4>Problem 2: ECLIPSE_HOME</h4><p>The test suites need to know where the root of the eclipse install is on the
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   260
file system (the ECLIPSE_HOME variable). However, this variable is only defined
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   261
in JDT. The ${eclipse-home} property can be set to a reasonable default inside
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   262
of the test.xml script. Then tests can be run from the standard Ant window,
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   263
without having to specify -Declipse-home=%ECLIPSE_HOME%. If a value for
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   264
${eclipse-home} does get passed in, the default (specified in test.xml) gets
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   265
overridden. The parameter is passed in by the build mechanism. For most cases,
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   266
the value &quot;${basedir}/../..&quot; is a reasonable default.</p><h4>Problem 3: Ugly reference to library.xml</h4><p>org.eclipse.test should provide Ant tasks, not template scripts.</p><h4>Problem 4: No console output</h4><p>When you run a TestSuite using the standard JUnit, it normally outputs a
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   267
series of dots to the console so that you can track the TestSuite's progress.
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   268
It is not possible to add this feature to the automated testing process at this
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   269
point in time.</p><h4>Problem 5: Ant java task on Linux</h4><p>Ant expects there to be a java executable on the system path. Furthermore, the executable
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   270
must be a real file, not a symbolic link. If the test framework is throwing an exception
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   271
<code>java.io.IOException: java: not found</code>, ensure that the java executable is on
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   272
your system path.</p><h4>Problem 6: PDE</h4><p>The testing framework currently has no knowledge of PDE. In order to run the automated
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   273
you must be running a self hosting environment with a full development and target Eclipse.</p>
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   274
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   275
</body>
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   276
0c11af94aac6 add files for RCL_2_2
cawthron
parents:
diff changeset
   277
</html>