Where should I put the test code for the Eclipse plugin snippet?

There are several posts I found while searching for best practice where to put test code for an Eclipse plugin. Most of them offer snippets like this

I have one single source plugin and two snippets, one for RCP and one for RAP.

Now, if I create another snippet for testing, I cannot access the RCP API from the test snippet.

There is a header Eclipse-ExtensibleAPI

, if set to true, the host plugin will make its fragment APIs available. But it is available for other plugins that require it and not its own snippet (test snippet).

Can anyone help me with this?

+2


source to share


1 answer


This issue is a consequence of Eclipse's convention of testing separate projects. The purpose of this separation is to eliminate test dependencies like JUnit, mocking frameworks, etc. From the main project. However, this reasoning is based on assumptions that are becoming increasingly obsolete. If you are not using PDE assembly or plug-in tests, you might consider moving the tests into the same project that contains the source code.

I believe that unit tests belong to the project source code and should not be separated. Anyone who checks the source code should have tests as well.

PDE build

Eclipse plug-in projects that were built with PDE build , which reads dependencies from a manifest file and cannot distinguish between test area and compilation-specific dependencies. Although the PDE assembly is still used internally by the IDE for export, it has been replaced by tycho in most Eclipse projects, including the platform itself. Tycho is based on Maven which allows you to use test dependencies that do not fall into the built artifact.



If you move tests to the main project, you can add test dependencies to the project build path, or see if you can use m2e to manage dependencies.

Plug-in tests

Another assumption that led to the separation of tests was that all tests are executed as so-called test plug-ins. Testing plugins requires a working OSGi environment and can be considered more integrated than unit tests. Those tests should not be able to access the internal fragments, but test the functionality of the host node with whatever fragment is available in the environment.

Tests with regular modules do not require the OSGi framework, so they still use the same classloader and therefore do not need to be stored in fragments. If you build with tycho you need to use maven-surefire instead of tycho-surefire, as the latter runs tests as mock tests.

+4


source







All Articles