Difference between revisions of "SMILA/Documentation/HowTo/Create a test bundle (plug-in)"

From Eclipsepedia

Jump to: navigation, search
(New page: This page descibes how to create a new test bundle for SMILA. The description on how to add a plug-in bundle can be found in [[SMILA/Development_Guidelines/Create a bundle (plug-in)|How t...)
 
(Create a test suite file)
(18 intermediate revisions by 4 users not shown)
Line 1: Line 1:
This page descibes how to create a new test bundle for SMILA.
+
This page descibes how to create a new test bundle for SMILA.The description on how to add a plug-in bundle can be found in [[SMILA/Development Guidelines/Create a bundle (plug-in)|How to create a bundle (plug-in)]]. This HowTo is similar with only minor differences.  
  
The description on how to add a plug-in bundle can be found in [[SMILA/Development_Guidelines/Create a bundle (plug-in)|How to create a bundle (plug-in)]]. This how to will be much the same with only minor differences.
+
== Create the test bundle ==
  
== Create the empty project ==
+
The following steps must be performed to create the test project base:<br>
  
The following steps must be performed to create the test project base:
+
#Launch Eclipse and select your SMILA workspace.
 +
#Select ''File &gt; New &gt; Project''and click ''Plug-in Project''.
 +
#Click ''Next''. <br>Now you have to fill in various metadata and settings for your plug-in project. You may as well edit some of the settings later on by opening the <tt>MANIFEST.MF</tt> file with the ''Plug-in Manifest'' editor.
 +
#Enter a project name (you should use the same name as the bundle that should be tested and append a <tt>.test</tt> to it, for this example we will use <tt>org.eclipse.smila.integration.bundle.test</tt>).
 +
#Add <tt>code</tt> as a parent to the source and output folder:
 +
#*Set ''Source folder'' to <tt>code/src</tt>.
 +
#*Set ''Output folder'' to <tt>code/bin</tt>.
 +
#Set ''Target Platform'' to <tt>an OSGi framework: Equinox</tt>.
 +
#Click ''Next''.
 +
#Fill in the metadata information for the new bundle. Set the plug-in's name as ID, your bundle's version, a reasonable bundle name and the information about the provider (i.e. you). For our example we select:
 +
#*ID: <tt>org.eclipse.smila.integration.bundle.test</tt> (in our example)
 +
#*Version: <tt>1.0.0</tt>
 +
#*Name: <tt>Example Bundle Plugin Test</tt>
 +
#*Provider: <tt>Example company</tt>
 +
#*Exection Environment: <tt>JavaSE-1.7</tt>
 +
#Normally you won't need an activator in the test bundle, so uncheck this option.
 +
#Click ''Next''.
 +
#Uncheck the Option ''Create a plug-in using one of the templates''.
 +
#Click ''Finish''.
  
=== Select the New Project wizard ===
+
== Create a test suite file  ==
Launch eclipse, invoke the ''New Project'' wizard (menu ''File > New > Project''), and click ''Plug-in project''.
+
  
Click ''Next''.
+
Now you should create a test suite in your test bundle.  
  
Now you have to fill in various metadata and settings for your plug-in project. You can edit these later on by opening the MANIFEST.MF with the Plug-in Manifest Editor.
+
#Open your <tt>MANIFEST.MF</tt> file.
 +
#Switch to the ''Dependencies'' page.
 +
#In ''Imported Packages'' click ''Add''.
 +
#Add <tt>junit.framework</tt>.
 +
#Save <tt>MANIFEST.MF</tt>.
 +
#Create a package in <tt>code/src</tt> with the same name as your bundle (in our example it is <tt>org.eclipse.smila.integration.bundle.test</tt>).
 +
#Add an empty test suite named <tt>AllTests.java</tt>. <br> Here you can add all your bundle's tests after you've created them.
  
=== Define Plug-in Project settings ===
+
Since SMILA 1.1 you can also use the Junit4 annotations to define test suites and cases, you will need to import these additional packages at least
Set the Plug-in Project settings:
+
* <tt>org.junit</tt>
* Enter a project name (you should use the same name as the bundle that should be tested and add a <tt>.test</tt> to it, for this example we will use <tt>org.eclipse.smila.integration.bundle.test</tt>).
+
* <tt>org.junit.runner</tt>
* add <tt>code</tt> to the source and output folder:
+
* <tt>org.junit.runners</tt>
** set Source folder to <tt>code/src</tt>
+
However, because the Eclipse Testing Framework uses an workaround to execute JUnit4 tests (for details see [https://bugs.eclipse.org/bugs/show_bug.cgi?id=298619]), you must keep the Import-Package entry for <tt>junit.framework</tt> or the test bundle will not work in the headless build process. Check bundle <tt>org.eclipse.smila.clusterconfig.simple.test</tt> for an example.
** set Output folder to <tt>code/bin</tt>
+
* set Target Platform to <tt>an OSGi framework: Equinox</tt>
+
  
Click ''Next''.
+
== Prepare the testing gear  ==
  
=== Define Plug-in Content settings ===
+
Now you have to make some additions to the project in order to be able to integrate it into the build process or create plug-in test launchers.  
Fill in the metadata information for the new bundle.
+
  
Set the Plug-in's name as ID, your bundle's version, a reasonable bundle name and the information about the provider (i.e. you).
+
=== Create the launcher  ===
  
For our example:
+
#Create a <tt>configuration</tt> folder in your test bundle's root folder.
* ID: <tt>org.eclipse.smila.integration.bundle.test</tt> (in our example)
+
#Add this configuration folder to your <tt>build.properties</tt>.
* Version: <tt>1.0.0</tt>
+
#Add a <tt>log4j.properties</tt> file to your <tt>configuration</tt> folder.
* Name: <tt>Example Bundle Plugin Test</tt>
+
#If you need plug-ins to be started for your test (which is normally the case), create a <tt>config.ini</tt> file in your <tt>configuration</tt> folder containing your OSGi bundles config.
* Provider: <tt>Example company</tt>
+
#Create a JUnit Plug-in Test launcher for your <tt>AllTests.java</tt> suite:  
* Exection Environment: <tt><No Execution Environment></tt>
+
#*Select ''Run'' &gt; ''Run Configurations''.
 +
#*Select the ''JUnit Plug-Test'' node and click ''New''.
 +
#*Set the name to the bundle's name (here: <tt>org.eclipse.smila.integration.bundle.test</tt>).
 +
#*On the ''Test'' page:  
 +
#**Select which class to test.
 +
#**Set the ''Test runner'' to <tt>JUnit 3</tt> or <tt>JUnit 4</tt>, depending on the style you have chosen.
 +
#*On the ''Arguments'' page:
 +
#**Set the ''Program arguments'' to <tt>-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl}</tt>.
 +
#**Set the ''VM arguments'' to <tt>-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger -Dlog4j.configuration=file:${eclipse_home}configuration/log4j.properties -Xms40m -Xmx256m</tt>.
 +
#**If you need additional configuration or test data files (files/folders you store in your configuration folder), you should also add the following parameter to the VM arguments: <tt>-Dorg.eclipse.smila.utils.config.root=./configuration</tt> (adding this parameter is a good idea in any case).
 +
#*On the ''Configuration'' panel:  
 +
#**If you have a <tt>config.ini</tt>, you have to reference it here:
 +
#***Check ''Use an existing config.ini file as a template''.
 +
#***Click ''Workspace'' and navigate to the config.ini (example path: <tt>${workspace_loc:org.eclipse.smila.integration.bundle.test/configuration/config.ini}</tt>).
  
Normally you won't need an activator in the test bundle, so uncheck this option.
+
''Hint:'' You can configure Eclipse to add VM arguments each time a launcher is created:
  
Click ''Next''.
+
#''Window ''--&gt; ''Preferences ''--&gt; ''Plug-in Development'' --&gt; ''Target Platform'' --&gt; ''Edit''.
 +
#On the ''Arguments'' page, you can set the VM arguments that will be added to each new launch configuration.
  
=== Templates ===
+
=== Include test bundle in build process  ===
Uncheck the Option ''Create a plug-in using one of the templates''.
+
  
Click ''Finish''.
+
To enable the build process (see [[SMILA/Development_Guidelines/Howto_build_a_SMILA-Distribution|How to build a SMILA distribution]]) to include your test bundle you should follow the instructions on [[SMILA/Development_Guidelines/How_to_integrate_test_bundle_into_build_process|how to integrate a test bundle into the build process]].
 
+
== Create a test suite file ==
+
Now you should create a test suite in your test bundle.
+
 
+
* Open your <tt>MANIFEST.MF</tt> file
+
* Switch to the ''Dependencies'' page.
+
* in ''Imported Packages'' click ''Add..''
+
* add <tt>junit.framework (3.8.2)</tt>
+
* Save <tt>MANIFEST.MF</tt>
+
* Create a package in code/src with the same name as your bundle (in our example <tt>org.eclipse.smila.integration.bundle.test</tt>).
+
* Add an empty test suite named <tt>AllTests.java</tt>
+
** Here you can add all your bundle's tests after you've created them.
+
 
+
== Prepare the testing gear ==
+
 
+
Now you have to make some additions to the project in order to be able to integrate it into the build process or create plug-in test launchers.
+
 
+
=== Prepare launcher ===
+
* Create a <tt>configuration</tt> folder in your test bundle's root folder.
+
* Add this configuration folder to your build.properties
+
* add a <tt>log4j.properties</tt> file in your configuration folder
+
* if you need plug-ins to be started for your test (which is normally the case), create a <tt>config.ini</tt> file in your configuration folder containing your OSGi bundles config.
+
* Create a JUnit Plug-in Test launcher for your AllTests.java suite.
+
* open the launcher
+
** Test panel:
+
*** set the name to the bundle's name (here: <tt>org.eclipse.smila.integration.bundle.test</tt>).
+
*** set the Test runner to <tt>JUnit 3</tt>
+
** Arguments panel:
+
*** set the Program arguments to <tt>-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl}</tt>
+
*** set the VM arguments to <tt>-Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger -Dlog4j.configuration=file:${eclipse_home}configuration/log4j.properties -Xms40m -Xmx256m</tt>
+
*** If you need additional configuration or test data files (files/folders you store in your configuration folder), you also add the following line to your VM arguments: <tt>-Dorg.eclipse.smila.utils.config.root=./configuration</tt>
+
**** (to add this line is a good idea in any case.)
+
** Configuration panel:
+
*** if you have a <tt>config.ini</tt>, you have to reference it here:
+
**** check ''Use an existing config.ini file as a template''
+
**** Point the location to your bundle's config.ini (example: <tt>${workspace_loc:org.eclipse.smila.integration.bundle.test/configuration/config.ini}</tt>).
+
 
+
''Hint:''
+
You can configure eclipse to add VM arguments each time a launcher is created:
+
* Window --> Preferences --> Plug-in Development --> Target Platform --> Edit...
+
** In the Arguments page you can set the VM arguments that will be added to each new launch configuration.
+
 
+
=== Prepare automated testing during build process ===
+
To enable the builder (using make.xml) to test your bundle automatically, you have to provide an ant file named <tt>test.xml</tt>. The easiest way is to copy one from an already existing test bundle (e.g. org.eclipse.smila.jobmanager.test).
+
 
+
* Copy the <tt>test.xml</tt> file to your test bundle's root folder.
+
* Edit the <tt>test.xml</tt> file:
+
** Set the <tt>plugin-name</tt> property to your test bundle's name (in our example: org.eclipse.smila.integration.bundle.test).
+
** Save the file.
+
* include <tt>test.xml</tt> in the test bundle's build.properties
+
  
 
[[Category:SMILA]]
 
[[Category:SMILA]]

Revision as of 04:18, 5 July 2012

This page descibes how to create a new test bundle for SMILA.The description on how to add a plug-in bundle can be found in How to create a bundle (plug-in). This HowTo is similar with only minor differences.

Contents

Create the test bundle

The following steps must be performed to create the test project base:

  1. Launch Eclipse and select your SMILA workspace.
  2. Select File > New > Projectand click Plug-in Project.
  3. Click Next.
    Now you have to fill in various metadata and settings for your plug-in project. You may as well edit some of the settings later on by opening the MANIFEST.MF file with the Plug-in Manifest editor.
  4. Enter a project name (you should use the same name as the bundle that should be tested and append a .test to it, for this example we will use org.eclipse.smila.integration.bundle.test).
  5. Add code as a parent to the source and output folder:
    • Set Source folder to code/src.
    • Set Output folder to code/bin.
  6. Set Target Platform to an OSGi framework: Equinox.
  7. Click Next.
  8. Fill in the metadata information for the new bundle. Set the plug-in's name as ID, your bundle's version, a reasonable bundle name and the information about the provider (i.e. you). For our example we select:
    • ID: org.eclipse.smila.integration.bundle.test (in our example)
    • Version: 1.0.0
    • Name: Example Bundle Plugin Test
    • Provider: Example company
    • Exection Environment: JavaSE-1.7
  9. Normally you won't need an activator in the test bundle, so uncheck this option.
  10. Click Next.
  11. Uncheck the Option Create a plug-in using one of the templates.
  12. Click Finish.

Create a test suite file

Now you should create a test suite in your test bundle.

  1. Open your MANIFEST.MF file.
  2. Switch to the Dependencies page.
  3. In Imported Packages click Add.
  4. Add junit.framework.
  5. Save MANIFEST.MF.
  6. Create a package in code/src with the same name as your bundle (in our example it is org.eclipse.smila.integration.bundle.test).
  7. Add an empty test suite named AllTests.java.
    Here you can add all your bundle's tests after you've created them.

Since SMILA 1.1 you can also use the Junit4 annotations to define test suites and cases, you will need to import these additional packages at least

  • org.junit
  • org.junit.runner
  • org.junit.runners

However, because the Eclipse Testing Framework uses an workaround to execute JUnit4 tests (for details see [1]), you must keep the Import-Package entry for junit.framework or the test bundle will not work in the headless build process. Check bundle org.eclipse.smila.clusterconfig.simple.test for an example.

Prepare the testing gear

Now you have to make some additions to the project in order to be able to integrate it into the build process or create plug-in test launchers.

Create the launcher

  1. Create a configuration folder in your test bundle's root folder.
  2. Add this configuration folder to your build.properties.
  3. Add a log4j.properties file to your configuration folder.
  4. If you need plug-ins to be started for your test (which is normally the case), create a config.ini file in your configuration folder containing your OSGi bundles config.
  5. Create a JUnit Plug-in Test launcher for your AllTests.java suite:
    • Select Run > Run Configurations.
    • Select the JUnit Plug-Test node and click New.
    • Set the name to the bundle's name (here: org.eclipse.smila.integration.bundle.test).
    • On the Test page:
      • Select which class to test.
      • Set the Test runner to JUnit 3 or JUnit 4, depending on the style you have chosen.
    • On the Arguments page:
      • Set the Program arguments to -os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl}.
      • Set the VM arguments to -Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger -Dlog4j.configuration=file:${eclipse_home}configuration/log4j.properties -Xms40m -Xmx256m.
      • If you need additional configuration or test data files (files/folders you store in your configuration folder), you should also add the following parameter to the VM arguments: -Dorg.eclipse.smila.utils.config.root=./configuration (adding this parameter is a good idea in any case).
    • On the Configuration panel:
      • If you have a config.ini, you have to reference it here:
        • Check Use an existing config.ini file as a template.
        • Click Workspace and navigate to the config.ini (example path: ${workspace_loc:org.eclipse.smila.integration.bundle.test/configuration/config.ini}).

Hint: You can configure Eclipse to add VM arguments each time a launcher is created:

  1. Window --> Preferences --> Plug-in Development --> Target Platform --> Edit.
  2. On the Arguments page, you can set the VM arguments that will be added to each new launch configuration.

Include test bundle in build process

To enable the build process (see How to build a SMILA distribution) to include your test bundle you should follow the instructions on how to integrate a test bundle into the build process.