When instrumenting junit, it throws ClassCastException
when running a test :
java.lang.ClassCastException: junit.framework.TestSuite
at
junit.runner.BaseTestRunner.getTest(BaseTestRunner.java:53)
at
junit.awtui.TestRunner.runSuite(TestRunner.java:393)
at
junit.awtui.TestRunner$4.actionPerformed(TestRunner.java:164)
at
java.awt.TextField.processActionEvent(TextField.java:513)
at
java.awt.TextField.processEvent(TextField.java:486)
at
java.awt.Component.dispatchEventImpl(Component.java:2593)
Logged In: YES
user_id=350104
Made a little further investigation on this. JUnit uses
Class.forName(...) construct to load Tests.
BaseTestRunner _was_ loaded with InstrumentingClassLoader.
In getTest() method,
Class.forName("junit.framework.TestSuite") was used, and
this loading resulted in TestSuite being loaded by a System
ClassLoader.
Logged In: YES
user_id=350104
Workaround :
Exclude following classes from instrumentation :
o junit.runner.TestCaseClassLoader
o junit.framework.Test
o junit.framework.AssertionFailedError
If using test.CallTrace, commandline becomes :
java
-Dexclude=junit.runner.TestCaseClassLoader:junit.framework.Test:junit.framework.AssertionFailedError
-Dinclude=junit.* test.CallTrace junit.ui.TestRunner
This workaround will enable one to inspect calls made within
junit. However, TestCases cannot be
inspected.