Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3
Include Page
apache-felix-ipojo-header
apache-felix-ipojo-header

HTML

<div class="content">

How to test iPOJO Components

Testing components is a required step in the application development process. This page explains strategies to test iPOJO-based components and applications.

Introduction

Basically, we can distinguish two 2 types of tests:

  • Unitary tests
  • Integration tests

...

Let's imagine a maven project (downloadable here). Unitary tests are placed in the src/test/java folder. You can use mock object as illustrated in the example. When you launch the mvn clean install command, maven compiles your classes and executes the tests. If the tests are executed successfully, the build process continues and creates the bundle as follows:

Code Block
xml
xml
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Dummy Component
[INFO]    task-segment: [clean, install]
[INFO] ------------------------------------------------------------------------
[INFO] [clean:clean]
[INFO] Deleting directory /Users/clement/Documents/workspaces/ipojo-dev/UnitaryTest/target
[INFO] [resources:resources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:compile]
[INFO] Compiling 1 source file to /Users/clement/Documents/
        workspaces/ipojo-dev/UnitaryTest/target/classes
[INFO] [resources:testResources]
[INFO] Using default encoding to copy filtered resources.
[INFO] [compiler:testCompile]
[INFO] Compiling 1 source file to /Users/clement/Documents/
        workspaces/ipojo-dev/UnitaryTest/target/test-classes
[INFO] [surefire:test]
[INFO] Surefire report directory: /Users/clement/Documents/
        workspaces/ipojo-dev/UnitaryTest/target/surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running org.apache.felix.ipojo.ut.component.test.MyTestCase
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.076 sec

Results :

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

[INFO] [bundle:bundle]
[INFO] [ipojo:ipojo-bundle {execution: default}]
[INFO] Start bundle manipulation
[INFO] Metadata file : /Users/clement/Documents/
  workspaces/ipojo-dev/UnitaryTest/target/classes/metadata.xml
[INFO] Input Bundle File : /Users/clement/Documents/workspaces/
  ipojo-dev/UnitaryTest/target/org.apache.felix.ipojo.test.dummy.component-1.1.0-SNAPSHOT.jar
[INFO] Bundle manipulation - SUCCESS
[INFO] [install:install]
[INFO] Installing /Users/clement/Documents/workspaces/
  ipojo-dev/UnitaryTest/target/org.apache.felix.ipojo.test.dummy.component-1.1.0-SNAPSHOT.jar 
  to /Users/clement/.m2/repository/ipojo/tests/org.apache.felix.ipojo.test.dummy.component/1.1.0-SNAPSHOT
  /org.apache.felix.ipojo.test.dummy.component-1.1.0-SNAPSHOT.jar
[INFO] [bundle:install]
[INFO] Parsing file:/Users/clement/.m2/repository/repository.xml
[INFO] Installing ipojo/tests/org.apache.felix.ipojo.test.dummy.component/
    1.1.0-SNAPSHOT/org.apache.felix.ipojo.test.dummy.component-1.1.0-SNAPSHOT.jar
[INFO] Writing OBR metadata
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6 seconds
[INFO] Finished at: Tue Oct 21 14:03:03 CEST 2008
[INFO] Final Memory: 11M/25M
[INFO] ------------------------------------------------------------------------

...

Once every component has its unitary test suite (isn't it?), you can go further and creates integration test. In order to check the behavior of the system, iPOJO provides the junit4osgi framework. This framework allows the executing of Junit test inside OSGi. Refer to the Junit4OSGi page to know how to use it.

Moreover, OPS4J Pax Exam can also be used to test iPOJO components.



Include Page
apache-felix-ipojo-footer
apache-felix-ipojo-footer