Where to put test classes?

47 Views Asked by At

When testing Eclipse RCP plugins, it is good practice to have all test classes and resources live in a dedicated (test) fragment. This way all classes in the host plugin can be accessed, no matter if those packages are actually exported or not.

But what if I have a common test infrastructure, that is used by many plugins?

I cannot put this into a fragment, since I cannot reuse classes inside a fragment somewhere else.

1

There are 1 best solutions below

0
On BEST ANSWER

A fragment does not exist at runtime. It is merged with its Fragment-Host.

You either need to place the code in a regular bundle/plug-in, or use a poxy bundle that exposes the classes of the fragment to be accessible from other fragments or bundles. For example:

Host

Bundle-SymbolicName: org.example.test.util
Eclipse-ExtensibleAPI: true

Fragment

Bundle-SymbolicName: org.example.test.util.impl
Export-Package: org.example.test.util.impl
Fragment-Host: org.example.test.util

However, the latter approach uses the Eclipse-specific Extensible-API header that is only understood by the Equinox OSGi implementation.

Therefore, my recommendation would be to leave the actual test classes in a fragment that corresponds to the bundle-under-test and put the reusable test helpers in a dedicated bundle.