?????????????з??????????????????
????1.??????????????η?????private????default????public?????????????
????2.???????????÷??????????????з??????????????
???????????
????????????????????????з????????????????????????÷??????в???.
????PS:???JUnit 3??
?????????????
????package com.mengdd.junit;
????public class Calculator2
????{
????private int add(int a?? int b)
????{
????return a + b;
????}
????}
??????????
package com.mengdd.junit;
import java.lang.reflect.Method;
import junit.framework.Assert;
import junit.framework.TestCase;
public class CalculatorTest2 extends TestCase
{
public void testAdd()
{
Calculator2 calculator2 = new Calculator2();
// ???class????
Class<Calculator2> clazz = Calculator2.class;
// ???????
try
{
Method method = clazz.getDeclaredMethod("add"?? new Class[] {
int.class?? int.class });// ???????????:Integer.TYPE
method.setAccessible(true);// ??????????η????????з??????????????
Object result = method.invoke(calculator2?? new Object[] { 2?? 3 });
Assert.assertEquals(5?? result);
}
catch (Exception e)
{
e.printStackTrace();
Assert.fail();
}
}
}