Chapter 7. Testing applications

 

This chapter covers

  • Migrating tests to OSGi for in-container testing
  • Mocking OSGi APIs for bundle testing
  • Performing unit, integration, and management testing

You’re now just about halfway through this book: congratulations! At this point, you should have confidence in applying OSGi to new and existing projects. Migrating applications to OSGi should be especially fresh in your mind from the last chapter. But what can you do to make sure you’re on the right track to modularity and not turning your applications into tangled spaghetti? As is true for any piece of software, the best way to track quality is with regular testing. Testing can confirm that your modularized code meets the same requirements as your original application. Testing can verify that your code will continue to work when deployed inside the target container. It can even help you practice different deployment scenarios in the safety of your friendly neighborhood test server. Even a simple nonfunctional test, such as checking the number of shared packages between bundles, can avoid tangles forming early on in development.

Why wait until the end of a project to discover if your code works in the strict environment of an OSGi framework or how well your chosen bundles fit together? Migrate and modularize your tests along with your code! This chapter will help put this advice into practice by taking you through three different approaches:

7.1. Migrating tests to OSGi

7.2. Mocking OSGi

7.3. Advanced OSGi testing

7.4. Summary