You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
AbstractRuleExtension uses ReflectionUtil.loadClassIfAvailable() to attempt to load JUnit 4 rule classes. ReflectionUtil attempts to load the classes in the context of spock-core which does not import junit4 packages. In an OSGi environment the rules classes are not on the classpath of the spock-core bundle .
To Reproduce
A specification with @Rule or other JUnit 4 rules
Specification is executed in an OSGi environment
Expected behavior
JUnit 4 rules work in OSGi
Actual behavior
JUnit4 extensions for rules do not function
Java version
Eclipse Adoptium 8.0.382.5
Buildtool version
Not applicable
What operating system are you using
Windows
Dependencies
spock-core 2.3-groovy-3.0
spock-junit4 2.3-groovy-3.0
Karaf 4.3.9
PaxExam 4.3.15
Additional context
It may make sense to have add a method to ReflectionUtil which a caller could provide a Class to use for loading, e.g. ReflectionUtil.loadClassIfAvailable(Class<?> cp, String className) which would use cp.getClassLoader() as opposed to ReflectionUtil.class.getClassLoader().
Callers outside of spock-core (e.g. spock-junit4) would provide their own context e.g. ReflectionUtil.loadClassIfAvailable(AbstractRuleExtension.class, "org.junit.Rule")
The text was updated successfully, but these errors were encountered:
@mpiggott adding an optional reference class for the ClassLoader for the ReflectionUtil methods makes sense. This would require overloads for all methods that use a classloader. A PR would be welcome.
Describe the bug
AbstractRuleExtension
usesReflectionUtil.loadClassIfAvailable()
to attempt to load JUnit 4 rule classes.ReflectionUtil
attempts to load the classes in the context ofspock-core
which does not import junit4 packages. In an OSGi environment the rules classes are not on the classpath of thespock-core
bundle .To Reproduce
@Rule
or other JUnit 4 rulesExpected behavior
JUnit 4 rules work in OSGi
Actual behavior
JUnit4 extensions for rules do not function
Java version
Eclipse Adoptium 8.0.382.5
Buildtool version
Not applicable
What operating system are you using
Windows
Dependencies
Additional context
It may make sense to have add a method to
ReflectionUtil
which a caller could provide aClass
to use for loading, e.g.ReflectionUtil.loadClassIfAvailable(Class<?> cp, String className)
which would usecp.getClassLoader()
as opposed toReflectionUtil.class.getClassLoader()
.Callers outside of
spock-core
(e.g.spock-junit4
) would provide their own context e.g.ReflectionUtil.loadClassIfAvailable(AbstractRuleExtension.class, "org.junit.Rule")
The text was updated successfully, but these errors were encountered: