Discussion:
[tycho-user] Getting a combination of JUnit4, Hamcrest, Mockito to work in Eclipse AND Tycho
Stephan Druskat
2017-07-20 14:12:34 UTC
Permalink
Dear List,

I've managed to get JUnit 4.12 + Hamcrest 1.3 + Mockito 2.8.47 to work
in Eclipse so that when I add them as dependencies, the tests will run.

(The way I've done this is using the p2-maven-plugin
(https://github.com/reficio/p2-maven-plugin/) to bundle the following
artifacts from Maven Central into plugins/a feature and provie them via P2:

https://github.com/reficio/p2-maven-plugin/
- junit 4.12
- org.mockito.mockito-core 2.8.47
- org.hamcrest.all 1.3.0
)

Adding the plugins to my test fragment as dependencies makes the tests
run in Eclipse.

However, the Tycho build of the same fragment will fail with the
following messages:

java.lang.LinkageError: loader constraint violation: loader (instance of
org/eclipse/osgi/internal/loader/EquinoxClassLoader) previously
initiated loading for a different type with name "org/hamcrest/Matcher"
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at
org.eclipse.osgi.internal.loader.ModuleClassLoader.defineClass(ModuleClassLoader.java:273)
at
org.eclipse.osgi.internal.loader.classpath.ClasspathManager.defineClass(ClasspathManager.java:632)
at
org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findClassImpl(ClasspathManager.java:586)
at
org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findLocalClassImpl(ClasspathManager.java:538)
at
org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findLocalClass(ClasspathManager.java:525)
at
org.eclipse.osgi.internal.loader.ModuleClassLoader.findLocalClass(ModuleClassLoader.java:325)
at
org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:345)
at
org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:423)
at
org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:372)
at
org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:364)
at
org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:161)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:12)
at org.junit.Assert.assertThat(Assert.java:956)
at org.junit.Assert.assertThat(Assert.java:923)

So it seems that some other plugin is loading the package
"org.hamcrest.Matcher" before this fragment does. This is probably due
to the import/export/partial import/partial export chaos surrounding the
JUnit/Hamcrest/Mockito setup.

Does anyone have an idea, or even better: a working example, of how to
get the three components work together both within the IDE (for quick
checks on whether tests run) and Tycho (for checks during the build?

Many thanks indeed!
Best
Stephan
Matthew Piggott
2017-07-20 14:19:50 UTC
Permalink
Not really answering your question but Orbit has both JUnit and Hamcrest -
http://download.eclipse.org/tools/orbit/downloads/drops/R20170516192513/

Mockito is there too but is an older version.
Post by Stephan Druskat
Dear List,
I've managed to get JUnit 4.12 + Hamcrest 1.3 + Mockito 2.8.47 to work
in Eclipse so that when I add them as dependencies, the tests will run.
(The way I've done this is using the p2-maven-plugin
(https://github.com/reficio/p2-maven-plugin/) to bundle the following
https://github.com/reficio/p2-maven-plugin/
- junit 4.12
- org.mockito.mockito-core 2.8.47
- org.hamcrest.all 1.3.0
)
Adding the plugins to my test fragment as dependencies makes the tests
run in Eclipse.
However, the Tycho build of the same fragment will fail with the
java.lang.LinkageError: loader constraint violation: loader (instance of
org/eclipse/osgi/internal/loader/EquinoxClassLoader) previously
initiated loading for a different type with name "org/hamcrest/Matcher"
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at
org.eclipse.osgi.internal.loader.ModuleClassLoader.
defineClass(ModuleClassLoader.java:273)
at
org.eclipse.osgi.internal.loader.classpath.ClasspathManager.defineClass(
ClasspathManager.java:632)
at
org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findClassImpl(
ClasspathManager.java:586)
at
org.eclipse.osgi.internal.loader.classpath.ClasspathManager.
findLocalClassImpl(ClasspathManager.java:538)
at
org.eclipse.osgi.internal.loader.classpath.ClasspathManager.
findLocalClass(ClasspathManager.java:525)
at
org.eclipse.osgi.internal.loader.ModuleClassLoader.findLocalClass(
ModuleClassLoader.java:325)
at
org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.
java:345)
at
org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(
BundleLoader.java:423)
at
org.eclipse.osgi.internal.loader.BundleLoader.findClass(
BundleLoader.java:372)
at
org.eclipse.osgi.internal.loader.BundleLoader.findClass(
BundleLoader.java:364)
at
org.eclipse.osgi.internal.loader.ModuleClassLoader.
loadClass(ModuleClassLoader.java:161)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:12)
at org.junit.Assert.assertThat(Assert.java:956)
at org.junit.Assert.assertThat(Assert.java:923)
So it seems that some other plugin is loading the package
"org.hamcrest.Matcher" before this fragment does. This is probably due
to the import/export/partial import/partial export chaos surrounding the
JUnit/Hamcrest/Mockito setup.
Does anyone have an idea, or even better: a working example, of how to
get the three components work together both within the IDE (for quick
checks on whether tests run) and Tycho (for checks during the build?
Many thanks indeed!
Best
Stephan
_______________________________________________
tycho-user mailing list
To change your delivery options, retrieve your password, or unsubscribe
from this list, visit
https://dev.eclipse.org/mailman/listinfo/tycho-user
Stephan Druskat
2017-07-20 14:27:17 UTC
Permalink
Thanks,

I've tried the Orbit bundles first of course, but they let the test fail
when running in the IDE:

- java.lang.SecurityException: class "org.hamcrest.Matchers"'s signer
information does not match signer information of other classes in the
same package

Thanks!
Stephan
Post by Matthew Piggott
Not really answering your question but Orbit has both JUnit and Hamcrest
- http://download.eclipse.org/tools/orbit/downloads/drops/R20170516192513/
Mockito is there too but is an older version.
Dear List,
I've managed to get JUnit 4.12 + Hamcrest 1.3 + Mockito 2.8.47 to work
in Eclipse so that when I add them as dependencies, the tests will run.
(The way I've done this is using the p2-maven-plugin
(https://github.com/reficio/p2-maven-plugin/
<https://github.com/reficio/p2-maven-plugin/>) to bundle the following
https://github.com/reficio/p2-maven-plugin/
<https://github.com/reficio/p2-maven-plugin/>
- junit 4.12
- org.mockito.mockito-core 2.8.47
- org.hamcrest.all 1.3.0
)
Adding the plugins to my test fragment as dependencies makes the tests
run in Eclipse.
However, the Tycho build of the same fragment will fail with the
java.lang.LinkageError: loader constraint violation: loader (instance of
org/eclipse/osgi/internal/loader/EquinoxClassLoader) previously
initiated loading for a different type with name "org/hamcrest/Matcher"
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at
org.eclipse.osgi.internal.loader.ModuleClassLoader.defineClass(ModuleClassLoader.java:273)
at
org.eclipse.osgi.internal.loader.classpath.ClasspathManager.defineClass(ClasspathManager.java:632)
at
org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findClassImpl(ClasspathManager.java:586)
at
org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findLocalClassImpl(ClasspathManager.java:538)
at
org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findLocalClass(ClasspathManager.java:525)
at
org.eclipse.osgi.internal.loader.ModuleClassLoader.findLocalClass(ModuleClassLoader.java:325)
at
org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:345)
at
org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:423)
at
org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:372)
at
org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:364)
at
org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:161)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:12)
at org.junit.Assert.assertThat(Assert.java:956)
at org.junit.Assert.assertThat(Assert.java:923)
So it seems that some other plugin is loading the package
"org.hamcrest.Matcher" before this fragment does. This is probably due
to the import/export/partial import/partial export chaos surrounding the
JUnit/Hamcrest/Mockito setup.
Does anyone have an idea, or even better: a working example, of how to
get the three components work together both within the IDE (for quick
checks on whether tests run) and Tycho (for checks during the build?
Many thanks indeed!
Best
Stephan
_______________________________________________
tycho-user mailing list
To change your delivery options, retrieve your password, or
unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/tycho-user
<https://dev.eclipse.org/mailman/listinfo/tycho-user>
_______________________________________________
tycho-user mailing list
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/tycho-user
Stephan Druskat
2017-07-21 09:48:13 UTC
Permalink
Thanks Hendrik,

We'll consider doing the same :).

Best
Stephan
Hi Stephan,
We provide the whole target platform as hosted P2-Repository for both
http://wiki.eclipse.org/Equinox/p2/Publisher#Features_And_Bundles_Publisher_Application
We are not using the p2-maven-plugin-way to generate dependencies "on
the fly". Would be neat to configure some kind of transformer comparable
to maven-shade-plugin, though.
Kind regards
Henrik
Thanks Hendrik,
Have you automated the "unsigning", e.g., with maven-jarsigner-plugin?
If so, could you please provide an example? That'd be great!
Many thanks
Stephan
Hi,
we ran into the same problem with non-matching signer information and
worked around that by stripping signer information from
org.hamcrest.core: META-INF\ECLIPSE_.RSA, META-INF\ECLIPSE_.SF and
trailing signer entries from manifest itself.
Kind regards
Henrik
Post by Stephan Druskat
Thanks,
I've tried the Orbit bundles first of course, but they let the test fail
- java.lang.SecurityException: class "org.hamcrest.Matchers"'s signer
information does not match signer information of other classes in the
same package
Thanks!
Stephan
Post by Matthew Piggott
Not really answering your question but Orbit has both JUnit and Hamcrest
-
http://download.eclipse.org/tools/orbit/downloads/drops/R20170516192513/
Mockito is there too but is an older version.
Dear List,
I've managed to get JUnit 4.12 + Hamcrest 1.3 + Mockito 2.8.47 to work
in Eclipse so that when I add them as dependencies, the tests will run.
(The way I've done this is using the p2-maven-plugin
(https://github.com/reficio/p2-maven-plugin/
<https://github.com/reficio/p2-maven-plugin/>) to bundle the following
artifacts from Maven Central into plugins/a feature and
provie them
https://github.com/reficio/p2-maven-plugin/
<https://github.com/reficio/p2-maven-plugin/>
- junit 4.12
- org.mockito.mockito-core 2.8.47
- org.hamcrest.all 1.3.0
)
Adding the plugins to my test fragment as dependencies makes the tests
run in Eclipse.
However, the Tycho build of the same fragment will fail with the
java.lang.LinkageError: loader constraint violation: loader (instance of
org/eclipse/osgi/internal/loader/EquinoxClassLoader) previously
initiated loading for a different type with name
"org/hamcrest/Matcher"
at java.lang.ClassLoader.defineClass1(Native Method)
at
java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at
org.eclipse.osgi.internal.loader.ModuleClassLoader.defineClass(ModuleClassLoader.java:273)
at
org.eclipse.osgi.internal.loader.classpath.ClasspathManager.defineClass(ClasspathManager.java:632)
at
org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findClassImpl(ClasspathManager.java:586)
at
org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findLocalClassImpl(ClasspathManager.java:538)
at
org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findLocalClass(ClasspathManager.java:525)
at
org.eclipse.osgi.internal.loader.ModuleClassLoader.findLocalClass(ModuleClassLoader.java:325)
at
org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:345)
at
org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:423)
at
org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:372)
at
org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:364)
at
org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:161)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at
org.hamcrest.MatcherAssert.assertThat(MatcherAssert.java:12)
at org.junit.Assert.assertThat(Assert.java:956)
at org.junit.Assert.assertThat(Assert.java:923)
So it seems that some other plugin is loading the package
"org.hamcrest.Matcher" before this fragment does. This is probably due
to the import/export/partial import/partial export chaos surrounding the
JUnit/Hamcrest/Mockito setup.
Does anyone have an idea, or even better: a working example, of how to
get the three components work together both within the IDE (for quick
checks on whether tests run) and Tycho (for checks during the build?
Many thanks indeed!
Best
Stephan
_______________________________________________
tycho-user mailing list
To change your delivery options, retrieve your password, or
unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/tycho-user
<https://dev.eclipse.org/mailman/listinfo/tycho-user>
_______________________________________________
tycho-user mailing list
To change your delivery options, retrieve your password, or
unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/tycho-user
_______________________________________________
tycho-user mailing list
To change your delivery options, retrieve your password, or
unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/tycho-user
Loading...