0

I have a maven tycho build (which is running fine) and I want now to add the already existing unit tests to the build setup.

The unit tests are organized in a way that each plugin has its test fragment. All tests are called from a single test suite which contains the tests suites of the fragments and these are containing the actual unit test classes. This is possible due to the Eclipse-ExtensibleAPI: true setting in Manifest.MF Each test fragment has its pom.xml which contains true to avoid executing tests twice. The test fragments are set as in main pom.xml. The main test plugin (which contains the main test suite) contains in its pom.xml an target platform extension (which is a feature containing the test fragments).

Now as soon as a tests is called which is written to test a protected method the tycho-surefire throws an java.lang.IllegalAccessException. In Eclipse the unit tests run fine (as unit tests, not as plugin unit tests!). I assume that somehow the classes and the test classes are loaded with different class loaders? Otherwise, since the test is contained in a fragment to the host plugin and the Eclipse-ExtensibleAPI: true should take care that the visibility is such that this should not happen? Therefor, I would expect tycho to detect fragments and that it is loading them in a way that they have the same visibility?!

Is there a way/strategy to avoid this behaviour? I know that tycho-surefire tests are executed in an OSGi environment. But what does that mean regarding class loading of fragments and the IllegalAccessException?

Any help is highly appreciated!

Thanks in advance!

SeHe
  • 1
  • 1
  • Due to the fact that Java 16 and 17 are more restrictive than previous versions, you might get an `IllegalAccessException` by just running it with Java 16 or 17+ whereas it runs fine with a lower Java version. If this does not help, please show a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) and tell the Java versions with which you run your Eclipse and Maven. – howlger Jun 09 '22 at 09:19
  • Thanks for the hint. I tried to set up a "simple" project to demonstrate (can be found here : https://github.com/Monstereye/tycho-test-example.git). What I found out so far is that if the package name is the same in the test fragment and the host plugin the tests are running fine without illegal access exception. At least in my test example but not in my huge real world project. I will investigate further and tell what I found out where the differences are. – SeHe Jun 09 '22 at 12:26

1 Answers1

0

I found the reason why it was not working.

There where two plugins (one containing the ui code, one the domain model code) and one test fragment. The test fragment was referring to the ui code plugin but contained also tests which tested classes from domain model code. The packages in the test fragment where named the same as where the packages within the two plugins. I can only make a guess but I think that is why it was working with junit called from within eclipse.

Within the OSGi environment the tycho-surefire tests are running this was not working anymore.

To solve this I split the one test fragment into two (one for each plugin), named the packages of the test classes the same as the packages in the plugin and then it worked as expected. This is also reflected in my short example project on github.

SeHe
  • 1
  • 1