Test Driven Development with OSGi - Balázs Zsoldos

26
Test Driven Development with OSGi Balázs Zsoldos

description

OSGi Community Event 2013 (http://www.osgi.org/CommunityEvent2013/Schedule) ABSTRACT

Transcript of Test Driven Development with OSGi - Balázs Zsoldos

Page 1: Test Driven Development with OSGi - Balázs Zsoldos

Test Driven Development with OSGi

Balázs Zsoldos

Page 2: Test Driven Development with OSGi - Balázs Zsoldos

Original motivation

Deployment time

2 minutes Internet time

10 minutes

Page 3: Test Driven Development with OSGi - Balázs Zsoldos

Coding time

Deployment time

Facebook time

“What was I doing?” time

Page 4: Test Driven Development with OSGi - Balázs Zsoldos

Reduce

deployment

time

v3

Page 5: Test Driven Development with OSGi - Balázs Zsoldos

“mvn package”

+

copy file

Iteration is faster, but not fast enough (compile + copy)

Page 6: Test Driven Development with OSGi - Balázs Zsoldos

drop JAR

OR

Drop project

process

“target/classes”

Page 7: Test Driven Development with OSGi - Balázs Zsoldos

Eclipse

+

maven-bundle-plugin

=

up-to-date “target/classes”

Page 8: Test Driven Development with OSGi - Balázs Zsoldos

Richconsole deployment

OSGi container

Bundle A (startLevel=4)

Bundle B (startLevel=2)

StartLevel 10

StartLevel 2B

AA

Page 9: Test Driven Development with OSGi - Balázs Zsoldos

Deployment time reduced

How can we have better quality?

Page 10: Test Driven Development with OSGi - Balázs Zsoldos
Page 11: Test Driven Development with OSGi - Balázs Zsoldos

The Three Laws of TDD

1.You are not allowed to write any production code until you have first

2.You are not allowed to write more of a unit test than is sufficient to

3.You are not allowed to write more production code that is sufficient

The Clean Coder (Chapter 5)

Page 12: Test Driven Development with OSGi - Balázs Zsoldos

Test runner

Framework Startup

Blocker

Blueprint

Blocker

JUnit4

TestEngine

External Blockers External Test Engines

Page 13: Test Driven Development with OSGi - Balázs Zsoldos

Test runner

Test service

service.id=MyTest

service.testEngine=junit4

JUnit4

TestEngine

Blueprint / DS / creation from Acvtivator / ...

Page 14: Test Driven Development with OSGi - Balázs Zsoldos

I do not want to re-run all tests during

development

In development mode only tests with

@TestMethodInDevelopmentMode or

@TestClassInDevelopmentMode runs.

I do not want to re-run all tests during

development

Page 15: Test Driven Development with OSGi - Balázs Zsoldos

Test Code

Production code

Deploy / Run tests

Page 16: Test Driven Development with OSGi - Balázs Zsoldos

Test Code

Production code

Deploy / Run tests

What will run the tests on Jenkins?

Page 17: Test Driven Development with OSGi - Balázs Zsoldos

Maven repository

Get the dist package

File system

- Unpack dist package

- Parse with velocity

- Add the dependencies

eosgi-maven-plugin:dist

Page 18: Test Driven Development with OSGi - Balázs Zsoldos

Maven repository

eosgi-maven-plugin:integration-test

Get the dist package

File system

- Unpack dist package

- Parse with velocity

- Add the dependencies

- with testrunner

- as symbolic links

Start the container

Collect test results

Page 19: Test Driven Development with OSGi - Balázs Zsoldos

<plugin><groupId>org.everit.osgi.dev</groupId><artifactId>eosgi-maven-plugin</artifactId><version>1.1.3-SNAPSHOT</version><configuration>

<environments><environment>

<id>equinoxtest</id><framework>equinox</framework>

</environment></environments>

</configuration></plugin>

# Default environments in META-INF/eosgi-framework.properties

equinox=org.everit.osgi.dist:eosgi-dist-equinox:3.7.2-v201309190021equinox-3.7.2=org.everit.osgi.dist:eosgi-dist-equinox:3.7.2-v201309190021

Maven plugin configuration

Page 20: Test Driven Development with OSGi - Balázs Zsoldos

<plugin><groupId>org.everit.osgi.dev</groupId><artifactId>eosgi-maven-plugin</artifactId><version>1.1.3-SNAPSHOT</version><configuration>

<environments><environment>

<id>equinoxtest</id><framework>equinox</framework><vmOptions>

<vmOption>-Xdebug</vmOption><vmOption>-Xrunjdwp:server=y\,transport=dt_socket\,address=4000\,suspend=n</vmOption>

</vmOptions></environment>

</environments></configuration>

</plugin>

<plugin><groupId>org.everit.osgi.dev</groupId><artifactId>eosgi-maven-plugin</artifactId><version>1.1.3-SNAPSHOT</version><configuration>

<environments><environment>

<id>equinoxtest</id><framework>equinox</framework><systemProperties>

<myProperty1>myValue1</myProperty1><myProperty2>myValue2</myProperty2>

</systemProperties></environment>

</environments></configuration>

</plugin>

Maven plugin configuration

Page 21: Test Driven Development with OSGi - Balázs Zsoldos

<plugin><groupId>org.everit.osgi.dev</groupId><artifactId>eosgi-maven-plugin</artifactId><version>1.1.3-SNAPSHOT</version><configuration>

<environments><environment>

<id>equinoxtest</id><framework>equinox</framework><timeout>300000</timeout><bundleStartLevel>4</bundleStartLevel><frameworkStartLevel>4</frameworkStartLevel><bundleSettings>

<bundle><symbolicName>myBundle</symbolicName><version>1.0.0</version><startLevel>3</startLevel>

</bundle></bundleSettings>

</environment></environments>

</configuration></plugin>

Maven plugin configuration

Page 22: Test Driven Development with OSGi - Balázs Zsoldos

<plugin><groupId>org.everit.osgi.dev</groupId><artifactId>eosgi-maven-plugin</artifactId><version>1.1.3-SNAPSHOT</version><executions>

<execution><id>integration-test</id><phase>integration-test</phase><goals>

<goal>integration-test</goal></goals><configuration>

<jacoco><includes>org.everit.osgi.servicereference.*</includes><excludes>org.everit.osgi.servicereference.tests.*</excludes>

</jacoco><environments>

<environment><id>equinoxtest</id><framework>equinox</framework><vmOptions>

<vmOption>-Xdebug</vmOption><vmOption>-Xrunjdwp:server=y\,transport=dt_socket\,address=4000\,suspend=n</vmOption>

</vmOptions></environment>

</environments></configuration>

</execution></executions>

</plugin>

Maven plugin configuration

Page 23: Test Driven Development with OSGi - Balázs Zsoldos

100% coverage

Page 24: Test Driven Development with OSGi - Balázs Zsoldos

Let's see it in practice

Page 25: Test Driven Development with OSGi - Balázs Zsoldos

Creating your own dist package

●Look at the sample equinox package

●Look at the .eosgi.dist.xml file

●Look for the XSD in eosgi-maven-plugin sources and

read the documentation

●Velocity variables

– .eosgi.dist.xml

● bundleArtifacts: List<DistributableBundleArtifact>

● environment: EnvironmentConfiguration

–Parseable files

Page 26: Test Driven Development with OSGi - Balázs Zsoldos

Thank you

http://github.com/everit-org

[email protected]:

Source:

Maven repo: http://repository.everit.biz/nexus/content/groups/public