物联网项目

1.JUnit测试,私有类的测试

package com.message.service;

import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import org.junit.Test;

public class BaseTestCase {
protected Object invokeUnPublicMethod(Object pInstance, String pMethodName, Class[] paramTypes, Object[] parmValues) throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, InvocationTargetException{
Object result = null;
//MessageHandler h = new MessageHandler();
Method m = pInstance.getClass().getDeclaredMethod(pMethodName, paramTypes);
m.setAccessible(true);

result = m.invoke(pInstance,parmValues);
m.setAccessible(false);
System.out.println(result);
return result;
}
}

posted on 2013-10-29 22:38  张叫兽的技术研究院  阅读(163)  评论(0编辑  收藏  举报

导航