The reason is that the XML framework tries to instantiate classes using reflection and does this from the thread context classloader (PowerMock's classloader) but then tries to assign the created object to a field not loaded by the same classloader. When this happens you need to make use of the @PowerMockIgnore annotation to tell PowerMock to defer the loading of a certain package to the system classloader. What you need to ignore is case specific but usually it's the XML framework or some packages that interact with it. E.g. @PowerMockIgnore({"org.xml.*", "javax.xml.*"}).
從上述描述中可以得到的信息是,假如待測試類中使用到了XML解析相關的包和類,那么測試類前同樣需要增加@PowerMockIgnore({"org.xml.*", "javax.xml.*"}),消除類加載器引入的ClassCastException。