Closed GoogleCodeExporter closed 8 years ago
Indeed Surefire 2.9 changed the way classloading happens. With most setups the
following should work (assuming the unit test class is called MyUnitTest):
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.addUrls(ClasspathHelper.forClass(MyUnitTest.class));
// other configuration options here...
Reflections r = new Reflections(cb);
Original comment by stephan...@gmail.com
on 28 Jan 2012 at 3:49
This bit me -- everything was running fine in the IDE, then I maven tested and
bang.
Stephen's comment was very helpful; setting the URL's fixes it. Thanks.
I discovered a few things that might be useful in constructing the set of
URL's. These both seem to pick up what I wanted (which was all my classes):
ClasspathHelper.forPackage("com.mycompany") // GOOD
ClasspathHelper.forJavaClassPath() // GOOD
Whereas this picks up the JARs/dirs being _tested_ but not dependencies:
ClasspathHelper.forPackage("") // MAYBE what you want
And this just picks up java (system) JARs and a
target/surefire/surefirebooter####.jar:
ClasspathHelper.forClassLoader(getClass().getClassLoader()) // BAD
HTH.
Original comment by alex.hen...@cloudsoftcorp.com
on 24 Nov 2012 at 10:36
any comments on that before this issue is closed?
Original comment by ronm...@gmail.com
on 20 Feb 2013 at 9:25
Original issue reported on code.google.com by
ig...@interlink-ua.com
on 28 Jan 2012 at 11:37