使用junit的简单问题

lywei123 2004-03-31 06:10:54
这几段话怎么理解?需要被测试的代码写在什么地方?

1.Create a subclass of TestCase:
package junitfaq;

import java.util.*;
import junit.framework.*;

public class SimpleTest extends TestCase {

public SimpleTest(String name) {
super(name);
}

2.Write a test method to assert expected results on the object under test:
public void testEmptyCollection() {
Collection collection = new ArrayList();
assertTrue(collection.isEmpty());
}


3.Write a suite() method that uses reflection to dynamically create a test suite containing all the testXXX() methods:
public static Test suite() {
return new TestSuite(SimpleTest.class);
}





4.Write a main() method to conveniently run the test with the textual test runner:
public static void main(String args[]) {
junit.textui.TestRunner.run(suite());
}
}



...全文
55 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
煜知搬砖者 2004-03-31
  • 打赏
  • 举报
回复
http://www.javaresearch.org/article/showarticle.jsp?column=31&thread=6745
煜知搬砖者 2004-03-31
  • 打赏
  • 举报
回复
需要被测试的代码就是你得业务逻辑阿,呵呵
煜知搬砖者 2004-03-31
  • 打赏
  • 举报
回复
1.任何一个测试类都要继承TestCase
2.写一个明确的断言方法来测试结果返回值
3. 用测试套件去管理多个测试,它动态映射成一个套件容器其中包含了所有的测试
4.写一个主函数main()以次可以方便的用命令行来进行测试

62,612

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧