码迷,mamicode.com
首页 > 其他好文 > 详细

PowerMockito使用PowerMockIgnore注解消除类加载器引入的ClassCastException

时间:2020-01-10 01:02:56      阅读:110      评论:0      收藏:0      [点我收藏+]

标签:载器   测试   classes   not   loader   ota   system   spec   cep   

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。

PowerMockito使用PowerMockIgnore注解消除类加载器引入的ClassCastException

标签:载器   测试   classes   not   loader   ota   system   spec   cep   

原文地址:https://www.cnblogs.com/nizuimeiabc1/p/12174034.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!