Menu

Installation

Installing and running the examples

Download the following files from the OSGiUnit download page:

The osgiunit.externals.jar file needs to be extracted using the following command:

jar -xvf osgiunit.externals.jar

Alternatively you may check out the osgiunit and osgiunit.externals projects from the Subversion repository.

The following example projects are available:

  • osgiunit.examples - a sample service and OSGiUnit tests
  • osgiunit.groovyexamples (optional) - a sample service and OSGiUnit tests implemented in Groovy (you will need the Groovy Eclipse Plugin when opening this project in Eclipse)

Checkout the projects from trunk or tags directory of the projects Subversion.

All projects should be checked out into subdirs of the same directory. The subdirs should be named like the projects. When you're using Eclipse, it would be a good idea to put these projects into your workspace.

Verify and adjust the classpath in the build.xml files of the examples projects (see entries listed below) - they should point to the jar files downloaded and extracted above.

When using Eclipse, you may also need to adjust your build path settings in the project properties. Make sure that the JRE System Library entry points to a JRE version 1.5 or higher. You should also check that the Compiler compliance level in the Java Compiler settings is set to 5.0 at least.

<path id="test.classpath">
  <pathelement location="${bin}" />
  <fileset dir="..">
     <include name="osgiunit/dist/osgiunit.jar" />
     <include name="osgiunit.externals/org.mozilla/js.jar" />
     <include name="osgiunit.externals/org.eclipse/org.eclipse.core.runtime_3.0.0.jar" />
     <include name="osgiunit.externals/org.eclipse/org.eclipse.osgi.jar" />
     <include name="osgiunit.externals/org.eclipse/org.eclipse.osgi.services.jar" />
     <include name="osgiunit.externals/org.junit/junit.jar" />
  </fileset>
</path>

Running the examples using ant

When using the osgiunit source project, the jar file has to be created first. Change to the osgiunit directory and call ant clean compile dist.

Then change to the osigunit.examples or osgiunit.groovyexamples subdir and run ant JUnit.

Example:

 cd osgiunit
 ant clean compile dist
 cd ../osgiunit.examples
 ant JUnit

The output should look similar to this:

Buildfile: D:\home\joerg\development\osgiunit.examples\build.xml
-chkBin:
-mkBin:
compile:
    [echo] Compiled.
JUnit:
    [junit] testAdd()
    [junit] testSubstract()
    [junit] testAdd()
    [junit] testSubstract()
    [junit] testDivide()
    [junit] testMultiply()
    [junit] testAdd()
    [junit] testSubstract()
    [junit] Testsuite: de.cenit.os.osgiunit.examples.calcservice.test.AllTests
    [junit] Tests run: 7, Failures: 1, Errors: 3, Time elapsed: 8,422 sec
    [junit] ------------- Standard Output ---------------
    [junit] testAdd()
    [junit] testSubstract()
    [junit] testAdd()
    [junit] testSubstract()
    [junit] testDivide()
    [junit] testMultiply()
    [junit] testAdd()
    [junit] testSubstract()
    [junit] ------------- ---------------- ---------------
    [junit] Testcase: testAll took 2,391 sec
    [junit] Caused an ERROR
    [junit] expected:<4> but was:<5>
    [junit] junit.framework.AssertionFailedError: expected:<4> but was:<5>
    [junit] at de.cenit.os.osgiunit.examples.calcservice.test.service.CalcServiceTest.testSubstract(CalcServiceTest.java:59)
    [junit] at de.cenit.os.osgiunit.OSGiTestCase.runMethod(OSGiTestCase.java:201)
    [junit] at de.cenit.os.osgiunit.OSGiTestCase.runAllTests(OSGiTestCase.java:547)
    [junit] at de.cenit.os.osgiunit.examples.calcservice.test.TestCalcService1.testAll(TestCalcService1.java:43)
    [junit] Testcase: testAdd took 1,563 sec
    [junit] Testcase: testSubstract took 1,062 sec
    [junit] Caused an ERROR
    [junit] expected:<4> but was:<5>
    [junit] junit.framework.AssertionFailedError: expected:<4> but was:<5>
    [junit] at de.cenit.os.osgiunit.examples.calcservice.test.service.CalcServiceTest.testSubstract(CalcServiceTest.java:59)
    [junit] at de.cenit.os.osgiunit.OSGiTestCase.runMethod(OSGiTestCase.java:201)
    [junit] at de.cenit.os.osgiunit.examples.calcservice.test.TestCalcService2.testSubstract(TestCalcService2.java:64)
    [junit] Testcase: testDivide took 1,203 sec
    [junit] Caused an ERROR
    [junit] expected:<4> but was:<3>
    [junit] junit.framework.AssertionFailedError: expected:<4> but was:<3>
    [junit] at de.cenit.os.osgiunit.examples.calcservice.test.service.CalcServiceTest.testDivide(CalcServiceTest.java:78)
    [junit] at de.cenit.os.osgiunit.OSGiTestCase.runMethod(OSGiTestCase.java:201)
    [junit] at de.cenit.os.osgiunit.examples.calcservice.test.TestCalcService2.testDivide(TestCalcService2.java:69)
    [junit] Testcase: testMultiply took 1,125 sec
    [junit] Testcase: testAdd took 0,485 sec
    [junit] Testcase: testSubstract took 0,593 sec
    [junit] FAILED
    [junit] expected:<4> but was:<5>
    [junit] junit.framework.AssertionFailedError: expected:<4> but was:<5>
    [junit] at de.cenit.os.osgiunit.examples.calcservice.test.TestCalcService3.testSubstract(TestCalcService3.java:102)

BUILD FAILED
D:\home\joerg\development\osgiunit.examples\build.xml:47: Test de.cenit.os.osgiunit.examples.calcservice.test.AllTests failed

Total time: 10 seconds</pre>

Running the examples in Eclipse

Select osgiunit.examples.AllTests.launch in the package view of osgiunit.examples and choose Run As > Run ... from the context menu.

In the appearing dialog, select the osgiunit.examples.AllTests entry in the JUnit branch, then select the JRE tab and select your Java runtime environment.

Start the testcases by pressing the Run button.

Some of the testcases fail, the output of the JUnit view should look similar to this: