比如有这么一个程序:
public class calculator{
private static int a;
class inner{
inner(){
a=5;
}
}
int getResult(){
return a;
}
void clear(){
a=0;
}
}下面是一个最基本的我写的JUNIT
import static org.junit.Assert.*;import org.junit.Before;
import org.junit.Test;
public class calculatorTest { calculator a1 = new calculator();
@Before
public void setUp() throws Exception {
a1.clear();
} @Test
public void test() {
assertEquals(0,a1.getResult());
}}如何能够调用到inner,使得a的值变成5,然后用JUNIT测试?
public class calculator{
private static int a;
class inner{
inner(){
a=5;
}
}
int getResult(){
return a;
}
void clear(){
a=0;
}
}下面是一个最基本的我写的JUNIT
import static org.junit.Assert.*;import org.junit.Before;
import org.junit.Test;
public class calculatorTest { calculator a1 = new calculator();
@Before
public void setUp() throws Exception {
a1.clear();
} @Test
public void test() {
assertEquals(0,a1.getResult());
}}如何能够调用到inner,使得a的值变成5,然后用JUNIT测试?
assertEquals(0,a1.getResult());
a1.new inner().getResult()
}// 注意下你写的代码 规范,要不没人愿意看你的代码
好比,你写了一个类,我怎么测试啊,当然是new一个对象了,如果对象也没有,你说你怎么测。