Junit3 suite.addTest(new mytest()) 得到 'null' 错误
Junit3 suite.addTest(new mytest()) get 'null' error
我创建了一个测试套件并想添加一些新测试,但是 suite.addTest() 方法似乎没有像我预期的那样工作:
public static Test suite() {
TestSuite suite = new TestSuite(AllTests.class.getName());
//$JUnit-BEGIN$
// This line works
suite.addTestSuite(TestAdd.class);
// This line will cause a 'null' failure
suite.addTest(new TestAdd());
//$JUnit-END$
return suite;
}
测试地址代码:
import junit.framework.TestCase;
public class TestAdd extends TestCase {
public void test1()
{
assertEquals(1, 1);
}
}
我是不是漏掉了什么?
来自 Javadocs:
TestCase()
No-arg constructor to enable serialization. This method is not intended to be used by mere mortals without calling setName().
TestCase(java.lang.String name)
Constructs a test case with the given name.
看来您必须使用 TestCase 构造函数传递测试名称字符串。使用无参数构造函数旨在仅启用测试用例的序列化。
尝试:
suite.addTest(new TestAdd("add"));
我创建了一个测试套件并想添加一些新测试,但是 suite.addTest() 方法似乎没有像我预期的那样工作:
public static Test suite() {
TestSuite suite = new TestSuite(AllTests.class.getName());
//$JUnit-BEGIN$
// This line works
suite.addTestSuite(TestAdd.class);
// This line will cause a 'null' failure
suite.addTest(new TestAdd());
//$JUnit-END$
return suite;
}
测试地址代码:
import junit.framework.TestCase;
public class TestAdd extends TestCase {
public void test1()
{
assertEquals(1, 1);
}
}
我是不是漏掉了什么?
来自 Javadocs:
TestCase()
No-arg constructor to enable serialization. This method is not intended to be used by mere mortals without calling setName().
TestCase(java.lang.String name)
Constructs a test case with the given name.
看来您必须使用 TestCase 构造函数传递测试名称字符串。使用无参数构造函数旨在仅启用测试用例的序列化。
尝试:
suite.addTest(new TestAdd("add"));