首页| JavaScript| HTML/CSS| Matlab| PHP| Python| Java| C/C++/VC++| C#| ASP| 其他|
购买积分 购买会员 激活码充值

您现在的位置是:虫虫源码 > Java > 库访问java类的私有或受保护的部分

库访问java类的私有或受保护的部分

  • 资源大小:11.90 kB
  • 上传时间:2021-06-29
  • 下载次数:0次
  • 浏览次数:1次
  • 资源积分:1积分
  • 标      签: java 访问 部分 保护 私有

资 源 简 介

PrivilegedAccessor is a simple to use Java framework for accessing private methods, attributes, and constructors via reflection. Introduction In unit-testing you often need to prepare and later inspect the unit-under-test before you can test it. For instance you might need to inject mock-objects in your unit, so your unit-test does not access other units like backend systems. Or you might need to access a private attribute to assert a post-condition of a unit after the test. This could be easily done if Java had no modifiers like private. Accessing private (or protected or package private) methods, attributes, and constructors from outside is forbidden. And you should never change the modifiers of your production code just for unit-testing purposes!!! Fortunately we have reflection to access everything in our classes. Unfortunately reflection is somehow complicated: E

相 关 资 源

您 可 能 感 兴 趣 的

同 类 别 推 荐

VIP VIP