public class TestClassTest extends TestCase
{
TestClass testClassobject;
protected void setUp()throws Exception
{
super.setUp();
testClassobject=new TextClass();
}
}为什么要在JUnit SetUp方法中创建对象,在SetUp之前或之外可以吗创建对象吗?
各位高手 谢谢 !!!
{
TestClass testClassobject;
protected void setUp()throws Exception
{
super.setUp();
testClassobject=new TextClass();
}
}为什么要在JUnit SetUp方法中创建对象,在SetUp之前或之外可以吗创建对象吗?
各位高手 谢谢 !!!
{
TestClass testClassobject; TestClass tmp = new TestClass (); // setup之前protected void setUp()throws Exception
{
super.setUp();
testClassobject=new TextClass();
}
}
所以,还是写在setUp中比较好
public void setUp() throws Exception {
calc = new Calculation(); // 在测试开始前首先实例化一个Calculation对象
}上面的例子看到,在执行测试之前对calc引用进行实例化。这样的代码应该被放在测试之前执行,否则在测试过程中calc没有被初始化,它的值只能是null。
谢谢楼上 那几位大哥(大姐)了 。