Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "Virgo/Test"

Line 4: Line 4:
 
Virgo tests are implemented using JUnit and EasyMock. In addition, integration tests which require an OSGi environment use the Virgo test framework.
 
Virgo tests are implemented using JUnit and EasyMock. In addition, integration tests which require an OSGi environment use the Virgo test framework.
  
= Virgo Test Framework =
+
= Virgo Test Framework =
  
The Virgo Test Framework is maintained in its own [[Virgo/Source#Virgo_git_Repositories|git repository]]. It is fairly primitive as it provides just two test runners and an annotation.
+
The Virgo Test Framework is maintained in its own [[Virgo/Source#Virgo_git_Repositories|git repository]]. It is fairly primitive, providing just two test runners and an annotation.  
  
== Test Runners ==
+
== Test Runners ==
  
The test framework provides the following test runners.
+
The test framework provides the following test runners.  
  
=== OsgiTestRunner ===
+
=== OsgiTestRunner ===
  
The OsgiTestRunner is for testing components that need a simple OSGi environment. It is invoked via the JUnit @RunWith class annotation, for example:
+
The OsgiTestRunner is for testing components that need a simple OSGi environment. It is invoked via the JUnit @RunWith class annotation, for example:  
<pre>
+
<pre>import org.junit.runner.RunWith;
import org.junit.runner.RunWith;
+
 
import org.eclipse.virgo.test.framework.OsgiTestRunner;
 
import org.eclipse.virgo.test.framework.OsgiTestRunner;
  
Line 22: Line 21:
 
public class EventLogIntegrationTests { ...
 
public class EventLogIntegrationTests { ...
 
</pre>  
 
</pre>  
 +
OsgiTestRunner launches Equinox, installs the project containing the testcase class as a bundle, starts the bundle, and then runs the testcase class from inside the bundle using a standard JUnit runner.
  
OsgiTestRunner launches Equinox, installs the project containing the testcase class as a bundle, starts the bundle, and then runs the testcase class from inside the bundle using a standard JUnit runner.
+
=== DmKernelTestRunner  ===
  
=== DmKernelTestRunner ===
+
The DmKernelTestRunner, which should probably be renamed to VirgoKernelTestRunner, is for testing components that need a Virgo kernel environment complete with kernel and user regions. It must be used in combination with suitable configuration to launch the kernel bundles and the bundle on which the kernel depends.
  
The DmKernelTestRunner, which should probably be renamed to VirgoKernelTestRunner, is for testing components that need a Virgo kernel environment complete with kernel and user regions. It must be used in combination with suitable configuration to launch the kernel bundles and the bundle on which the kernel depends.
+
It is invoked via the JUnit @RunWith class annotation, for example:  
 
+
<pre>import org.junit.runner.RunWith;
It is invoked via the JUnit @RunWith class annotation, for example:
+
<pre>
+
import org.junit.runner.RunWith;
+
 
import org.eclipse.virgo.test.framework.dmkernel.DmKernelTestRunner;
 
import org.eclipse.virgo.test.framework.dmkernel.DmKernelTestRunner;
 
   
 
   
 
@RunWith(DmKernelTestRunner.class)
 
@RunWith(DmKernelTestRunner.class)
 
public abstract class AbstractKernelIntegrationTest { ...
 
public abstract class AbstractKernelIntegrationTest { ...
</pre>
+
</pre>  
 
+
The DmKernelTestRunner extends the function of the OsgiTestRunner to wait for the user region to start before running the testcase.  
The DmKernelTestRunner extends the function of the OsgiTestRunner to wait for the user region to start before running the testcase.
+
  
 
== Annotations  ==
 
== Annotations  ==
  
 
{| width="400" border="1" cellpadding="1" cellspacing="1"
 
{| width="400" border="1" cellpadding="1" cellspacing="1"
|+ Test Framework Annotations
+
|+ Test Framework Annotations  
 
|-
 
|-
! '''Annotation'''
+
! '''Annotation'''  
! '''Type'''
+
! '''Type'''  
! '''Purpose'''
+
! '''Purpose'''  
 
! '''Default Value'''
 
! '''Default Value'''
 
|-
 
|-
| ConfigLocation
+
| ConfigLocation  
| class
+
| class  
| Specifies the location from which the test framework should load its configuration
+
| Specifies the location from which the test framework should load its configuration  
 
| META-INF/test.config.properties
 
| META-INF/test.config.properties
 
|}
 
|}
Line 60: Line 56:
 
The test configuration file specifies a list of bundles to be installed and optionally started as well as kernel and other properties.  
 
The test configuration file specifies a list of bundles to be installed and optionally started as well as kernel and other properties.  
  
The Virgo web layer has a fairly typical [http://git.eclipse.org/c/virgo/org.eclipse.virgo.web.git/tree/org.eclipse.virgo.web.test/src/test/resources/META-INF/test.config.properties configuration file].
+
The Virgo web layer has a fairly typical [http://git.eclipse.org/c/virgo/org.eclipse.virgo.web.git/tree/org.eclipse.virgo.web.test/src/test/resources/META-INF/test.config.properties configuration file].  
  
== Utilities ==
+
== Utilities ==
  
The standard OSGi utility class FrameworkUtil is used to obtain the test bundle context as in the following example:
+
The standard OSGi utility class FrameworkUtil is used to obtain the test bundle context as in the following example:  
<pre>
+
<pre>protected final BundleContext testBundleContext = FrameworkUtil.getBundle(getClass()).getBundleContext();
protected final BundleContext testBundleContext = FrameworkUtil.getBundle(getClass()).getBundleContext();
+
 
</pre>
 
</pre>

Revision as of 07:53, 21 June 2010



Virgo tests are implemented using JUnit and EasyMock. In addition, integration tests which require an OSGi environment use the Virgo test framework.

Virgo Test Framework

The Virgo Test Framework is maintained in its own git repository. It is fairly primitive, providing just two test runners and an annotation.

Test Runners

The test framework provides the following test runners.

OsgiTestRunner

The OsgiTestRunner is for testing components that need a simple OSGi environment. It is invoked via the JUnit @RunWith class annotation, for example:

import org.junit.runner.RunWith;
import org.eclipse.virgo.test.framework.OsgiTestRunner;

@RunWith(OsgiTestRunner.class)
public class EventLogIntegrationTests { ...

OsgiTestRunner launches Equinox, installs the project containing the testcase class as a bundle, starts the bundle, and then runs the testcase class from inside the bundle using a standard JUnit runner.

DmKernelTestRunner

The DmKernelTestRunner, which should probably be renamed to VirgoKernelTestRunner, is for testing components that need a Virgo kernel environment complete with kernel and user regions. It must be used in combination with suitable configuration to launch the kernel bundles and the bundle on which the kernel depends.

It is invoked via the JUnit @RunWith class annotation, for example:

import org.junit.runner.RunWith;
import org.eclipse.virgo.test.framework.dmkernel.DmKernelTestRunner;
 
@RunWith(DmKernelTestRunner.class)
public abstract class AbstractKernelIntegrationTest { ...

The DmKernelTestRunner extends the function of the OsgiTestRunner to wait for the user region to start before running the testcase.

Annotations

Test Framework Annotations
Annotation Type Purpose Default Value
ConfigLocation class Specifies the location from which the test framework should load its configuration META-INF/test.config.properties

Test Configuration

The test configuration file specifies a list of bundles to be installed and optionally started as well as kernel and other properties.

The Virgo web layer has a fairly typical configuration file.

Utilities

The standard OSGi utility class FrameworkUtil is used to obtain the test bundle context as in the following example:

protected final BundleContext testBundleContext = FrameworkUtil.getBundle(getClass()).getBundleContext();

Copyright © Eclipse Foundation, Inc. All Rights Reserved.