??з???????????
???????????? ???????[ 2015/9/2 16:32:48 ] ?????????????????? private
?????????????з??????????????????
????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();
}
}
}
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11