It is assumed that you have basic knowledge of the Java programming language and you are acquainted with the OSGi Framework Specification and the unit testing framework JUnit version 3.8. Basic knowledge about Mockito mocking framework can be useful.
To write a TEE-specific test case for the JUnit Model, bear in mind the following:
To use BundleContext and thus interact with the OSGi framework, you need only to declare a public field of type org.osgi.framework.BundleContext in every class that extends the junit.framework.TestCase class.
Each test case has a specific structure that must be followed. It must have a root entry point that extends the junit.framework.TestSuite class. All tests should be added to this specific class using the addTestSuite method of the junit.framework.TestSuite class.
import junit.framework.TestSuite;
public final class JUnitTestSuite extends TestSuite {
public JUnitTestSuite(String name) { super(name); addTestSuite(JUnitTestCase1.class); addTestSuite(JUnitTestCase2.class); }
Here you can define the order of the execution of the added tests.
A configuration that follows the OSGi Framework Configuration Model can also be added to the test case. It is provided in a XML file and describes some preconditions that should be met before executing the test case. Most often it contains a list of bundles and some actions that must be done with them, for example install (and start) a required bundle. For further information about writing new test configurations for the OSGi Framework Configuration Model, refer to the Defining a New Test Configuration guide.
Since it is an OSGi-aware test case, it has a manifest file and is packed as an OSGi bundle. Except the manifest headers defined in the OSGi Service Platform Specification there are some TEE-specific ones. Following is a list of only the mandatory manifest headers that have specific values for the JUnit Model:
TFW-Name – Takes the JUnit value for this test case model.
TFW-Version – Enter 3.8.1 as a value for this required manifest header.
The values of the Target-Name and the Target-Version manifest headers are the same as for the Runtime Assertion Model.
It is not recommended to provide an implementation of the BundleActivator interface in your test cases.
Assertion methods must be used only in the main execution thread of the test case. For example, if you use an assertion in some of the OSGi-specific listeners and it fails, the exception that is thrown will not be logged in the TEE and also some functionality of the OSGi framework might be unpredictably changed.