java实体单元测试
2022/5/26 1:52:35
本文主要是介绍java实体单元测试,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
import org.junit.Test; import java.beans.Beans; import java.beans.PropertyDescriptor; import java.lang.reflect.Field; import java.lang.reflect.Method; public abstract class EntityTest<E> { protected abstract E getE(); private void execute() throws IllegalAccessException, InstantiationException { E e=getE(); Class aClass = e.getClass(); Object o = aClass.newInstance(); Field[] declaredFields = aClass.getDeclaredFields(); for (Field f: declaredFields ) { try{ if(f.isSynthetic()){ continue; } PropertyDescriptor propertyDescriptor = new PropertyDescriptor(f.getName(), aClass); Method readMethod = propertyDescriptor.getReadMethod(); Method writeMethod = propertyDescriptor.getWriteMethod(); writeMethod.invoke(o,readMethod.invoke(o)); }catch (Exception exc) { continue; } } } @Test public void invoke() throws InstantiationException, IllegalAccessException { this.execute(); } public class BeansTest extends EntityTest<Beans>{ @Override protected Beans getE() { return new Beans(); } } } 暂无找到出处,如有侵权,请联系删除。
这篇关于java实体单元测试的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-06-05做软件测试需要懂代码吗?
- 2024-06-0514-ShardingSphere的分布式主键实现
- 2024-06-03为什么以及如何要进行架构设计权衡?
- 2024-05-31全网首发第二弹!软考2024年5月《软件设计师》真题+解析+答案!(11-20题)
- 2024-05-31全网首发!软考2024年5月《软件设计师》真题+解析+答案!(21-30题)
- 2024-05-30【Java】百万数据excel导出功能如何实现
- 2024-05-30我们小公司,哪像华为一样,用得上IPD(集成产品开发)?
- 2024-05-30java excel上传--poi
- 2024-05-30安装笔记本应用商店的pycharm,再安排pandas等模块,说是没有打包工具?
- 2024-05-29java11新特性