A lightweight, reusable, extensible OSGi Application Testing Framework

Source: Internet
Author: User
Tags require

Introduction

OSGi is a java-based, runtime framework that provides dynamic module loading and management, which has been widely used in the industry. The OSGi framework uses Bundle to modularize complex applications. In the OSGi framework, the Bundle lifecycle is managed by the OSGi runtime environment, Bundle in loosely coupled forms, and Bundle with strict access security restrictions. But it is precisely because of these characteristics, to test these Bundle brought great difficulties. Many test cases require that the tested Bundle and their dependent Bundle run in the OSGi environment at the same time, and that if the test code and business code are to be separated, fine-grained unit tests cannot be performed due to the limitations of Bundle access rights. This article describes a lightweight, reusable, extensible OSGi application Testing Framework. The framework can perform traditional JUnit test code in an OSGi environment. It is possible to isolate test cases and business logic completely and without access security restrictions between Bundle, so that any granularity can be tested on this framework. The framework also provides a rich user interface (such as Telnet, Web pages, etc.) and test results reports, and users familiar with JUnit can use the framework without any obstacles to better test their OSGi applications.

OSGi is a java-based, runtime framework that provides dynamic module loading and management. OSGi provides the possibility for modularization and reuse of Java programs. Program modules can be dynamically loaded, started, stopped, and unloaded in the OSGi runtime framework, and the lifecycle of program modules is managed by the OSGi runtime framework. All program modules can be discovered and invoked with each other, and these components can be assembled together to work together in an OSGi running framework. As an industry standard, OSGi has been widely implemented and applied to many well-known products. For example, the famous Open-source IDE Eclipse is based on the OSGi Standard and provides its own implementation. For more information on OSGi, please refer to the links provided in resources.

The OSGi architecture provides a lot of convenience for modular development of Java programs and reuse of modules, but it is because of the limitations of architecture in OSGi that current Java test methods, such as JUnit, cannot be directly applied to the OSGI runtime framework.

Using Bundle in OSGi to define a program module, Bundle contains a set of Java classes and some additional descriptive information. The lifecycle of Bundle is maintained by the framework of OSGi, and the relationship between Bundle is often interdependent and invoked. So the test cases under OSGi need to run in the running framework of OSGi, and often require the interaction between multiple Bundle. The traditional JUnit test method does not provide a way to run test cases under OSGi.

Bundle has strict access restrictions on the Java packages it contains, and only a handful of interface packs can be accessed by other Bundle. In the test, we often need to test the Bundle of the package. How to avoid Bundle access restrictions, testing the Bundle inner pack becomes a new issue in OSGi testing.

In writing the test code, we always hope that the test code can be separated from the business code, which means that when the test case is run well, the product release does not require much work to detach the test code. In the OSGi framework, how to detach test code and business code without impacting the test code accessing business code is a new problem.

This article will introduce a lightweight, reusable, extensible OSGi test scenario for the above mentioned issues, with concrete examples to illustrate how to use the method.

Basic principle

As shown in Figure 1, we encapsulate the test code (testing Suite) in a separate Bundle run in OSGi. The test Framework Bundle is also provided to manage testing Bundle. The test Framework Bundle provides a user interface through which the user can run the appropriate test case and get the results.

Figure 1. Basic principles of test framework

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.