Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Testing OSGi the "groovy" way - Lars Pfannenschmidt, Dennis Nobel


Published on

OSGi Community Event 2013 (

In order to meet software project requirements, it is important to implement ongoing quality assurance using automated tests. However, for OSGi platforms which are used in various areas such as Embedded or Enterprise this turns out to be difficult. If several components need to be tested together, unit tests written in Java tend to reach their limits. Thus, implementing these tests can be very time consuming. Using the Groovy language, OSGi integration tests are efficient and easy to write, e.g. registering Groovy mocks as a OSGi Service turns out to be very handy. Hereby declarative OSGi components can be tested, too. Even if an OSGi application has to be CDC-compliant, tests can be written using Groovy in a modern syntax.

This presentation demonstrates how to implement Groovy tests for a sample OSGi project and how Groovy tests can be executed in an Equinox OSGi environment. Furthermore, it shows how a continuous integration solution using Maven Tycho can look like.

Lars Pfannenschmidt Interested in Mobile Applications, Smart Home, Domain Specific Languages, Machine Learning and agile development methodologies such as Scrum and Kanban. Senior Software Engineer and Founder of

Dennis Nobel Dennis works as an IT Consultant for itemis in the field of Java, Web and Mobile Development. Moreover he is interested in Agile Development, Continuous Integration, Modeling Technologies, Testing, IoT, Smart Home, OSGi and Groovy.

Published in: Technology
  • Be the first to comment

Testing OSGi the "groovy" way - Lars Pfannenschmidt, Dennis Nobel

  1. 1. EclipseCon Europe 2013 EHT IGSO GNITSET Y W YVOORG Lars Pfannenschmidt & Dennis Nobel
  2. 2. Lars Pfannenschmidt Senior Software Engineer at Level Up Analytics Intuit Founder of @mobilecgn
  3. 3. Dennis Nobel IT Consultant at itemis AG @itemis Java, Web and OSGi Developer
  4. 4. ENIG MI writing tests would make fun...
  5. 5. :1 NOITSEUQ Do you test your OSGi components?
  6. 6. : 2 NOITSEUQ Are you using Groovy?
  7. 7. Our Testing Story Embedded Device with CVM (~Java 1.4) OSGi framework (Prosyst mBS) Development with Eclipse CI Build with Maven and Tycho
  8. 8. How to write our tests?
  9. 9. Test Requirements Easy to write Modern language Type-safe access to Java classes Easy mocking Executable in Eclipse and Maven CI build Good IDE support No side effects for production code
  10. 10. V J Modern language? Not really...
  11. 11. What? Why Groovy?
  12. 12. Because we can!
  13. 13. YVOORG JVM Language Syntax Sugar Closures Less "Chatty"
  14. 14. Groovy JUnit Test Type inference, readable asserts, syntax sugar and more:        @et Ts vi 'ul pzawt BQsueol'){ od Bid iz ih B ac ny( dfpza=Pzaule.ePza) e iz izBidrnwiz( .ihac(B) wtSueBQ .ul( bid) asrTa pzasue i(B) setht, sBQ }      
  15. 15. How to test our OSGi Services?
  16. 16. Pizza Service Sample Services: PizzaService → PaymentService               pbi casPzaevcIp ipeet Pzaevc { ulc ls izSrieml mlmns izSrie @vrie Oerd pbi vi paere(ia Odrodr { ulc od lcOdrfnl re re) .. . ceiCrPyetevc.adernato(.) rdtadamnSriehnlTascin..; .. . } }          
  17. 17. STSET TINU +Executed fast +Focussed on the component ­No OSGi Runtime features ­Dependencies must be mocked ­No testing of declarative OSGi parts
  18. 18. STSET METSYS +Cover complete system +Real target environment +No mocking or special configuration ­Embedded device is needed (high execution effort) ­Slow execution ­Not focussed
  19. 19. STSET RENI TNOC NI Executed in OSGi environment Focussed on the component Testing of declarative OSGi parts Only partial mocking
  20. 20. ...we can not run Groovy in CVM
  21. 21. Why not use XONIUQE with a modern JVM?
  22. 22. YVOORG In-Container Testing with equinox
  23. 23. Mocking Simply transform a map to a proxy:               dfpyetevc =[ e amnSrie hnlTascin {Srn cmayd ln ceiCrNme adernato: tig opnI, og rdtadubr > asrTa cmayd i(qaT(LII_IZ_EVC') setht opnI, seulo'UGSPZASRIE) tascinald=tu rnatoCle re } ]a CeiCrPyetevc s rdtadamnSrie          
  24. 24. Register OSGi service mocks (1)               casPzaevcTs etnsOGTs { ls izSrieet xed Siet @vrie Oerd poetdBnlCnetgtudeotx( { rtce udeotx eBnlCnet) Atvtrcnet ciao.otx } .. . }          
  25. 25. Register OSGi service mocks (2)               @et Ts vi 'setta tehnlTascinmto i cle'){ od Asr ht h adernato ehd s ald( .. . rgseMc(amnSrie eitrokpyetevc) Pzaevc pzaevc =gtevc(izSrie izSrie izSrie eSriePzaevc) dfpza=Pzaule.ePza)wtSueSueBQ.ul( e iz izBidrnwiz(.ihac(ac.B)bid) dfcsoeIf =nwCsoeIf(MxMsemn" nwAdes) 44) e utmrno e utmrno"a utran, e drs(, 22 pzaevc.lcOdrnwOdrpza csoeIf) izSriepaere(e re(iz, utmrno) asrTa tascinald i(re setht rnatoCle, stu) }          
  26. 26. OSGiTest.groovy               dfrgseeSrie =[] e eitrdevcs : poetdasrc BnlCnetgtudeotx( rtce btat udeotx eBnlCnet) df<>Tgtevc(ls<>caz{ e T eSrieCasT lz) dfsrieeeec =bnlCnetgtevcRfrnecaznm) e evcRfrne udeotx.eSrieeeec( asrTa srieeeec,i(oNlVle) setht evcRfrne sntulau() bnlCnetgtevc(evcRfrne udeotx.eSriesrieeeec) } dfrgseMc(e mc,Hstbepoete =[] { e eitrokdf ok ahal rpris :){t).ae e nefcNm okcasitrae?fn(i}?nm asrTa itraeae i(oNlVle) setht nefcNm, sntulau() rgseeSrie.u(nefcNm, eitrdevcsptitraeae bnlCnetrgseSrieitraeae mc,poete) udeotx.eitrevc(nefcNm, ok rpris) } .. .          
  27. 27. NOIT MOTU with Maven and Tycho
  28. 28. Tycho Groovy configuration (1) Groovy & Maven Groovy Repository           <eoiois rpstre> .. . <eoioy rpstr> <dgov-cis<i> i>royelpe/d <aotp<lyu> lyu>2/aot <r>tp/ds.pigoreogrlaeGELPEe.//r> ulht:/itsrnsuc.r/ees/RCIS/43<ul <rpstr> /eoioy <rpstre> /eoiois          
  29. 29. Tycho Groovy configuration (2) Tycho, Groovy & Surefire               .. . <lgn pui> <rui>r.cis.yh<gopd gopdogelpetco/rui> <riatdtcosrfr-lgn/riatd atfci>yh-ueiepui<atfci> <eso>{yh.eso}/eso> vrin$tcovrin<vrin <ofgrto> cniuain <nlds icue> <nld>**/nld> icue*/<icue <icue> /nlds .. . <cniuain /ofgrto> <pui> /lgn .. .          
  30. 30. NOISULCNOC Add integrative Tests to your OSGi projects Easy to add groovy support in equinox and tycho Groovy makes developing tests more easier Powerful tests which run as fast as unit tests (>300 Tests in ~3 minutes) Fun!
  31. 31. UOY KN HT Checkout "groovy" OSGi testing at github:           $gtcoehts/gtu.o/roysitsiggt i ln tp:/ihbcmgovog/etn.i $c tsig d etn $mncenisal v la ntl       Lars Pfannenschmidt (Intuit, Inc.) Dennis Nobel (itemis AG) 1/32