使用suite()完善 测试代码

花了半小时在CSDN上写,点击”发表文章“,一片空白,这事特郁闷了,还得再写一遍,又花
半小时,再提交,又是空白,彻底死心了
Junit是一个优秀的java程序单元测试工具,我原先熟悉的框架是这样的:
//以一个jdbc测试程序为例
import junit.framework.TestCase;

public class TestClassName extends TestCase {

public void setUp() throws SQLException {
create connection;....................................(1)初始化
}

public void tearDown() throws SQLException {
drop the connection;.................................(2)撤销处理
}

public void test1030_Jdbc01() throws SQLException {
test case 1 ;...................................................(3a)
}

public void test1030_Jdbc01() throws SQLException {
test case 2 ;...................................................(3b)
}

public void test1030_Jdbc01() throws SQLException {
test case 3 ;..................................................(3c)
}

}

在Eclipe环境,右键--Run As--Junit Test就可以自动化测试了
实际执行的顺序是这样的:
(1)...(3a)...(2)...(1)...(3b)...(2)...(1)...(3c)...(2)
但是这几天因为要把程序放在linux上,没有了IDE,不能再右键点击这种简单的操作了,呵呵
所以,加上main()函数接口,需要使用suite()
import junit.framework.Test;
import junit.framework.TestSuite;
import junit.textui.TestRunner;

public static Test suite() {
TestSuite suite = new TestSuite("myCT");
suite.addTestSuite(TestClassName .class); ...(4)加载整个测试类的所有case
return suite;
}
public static void main(String[] args)
{
TestSuite testSuite=new TestSuite();
testSuite.addTest(suite());
TestRunner.run(testSuite); ...................................(5)run!
}
这样就能通过java -cp 这种方式自动化测试了

后记:

--不能习惯于套用别人的框架
--不能依赖IDE
--接触一个产品不妨看看它的官方Manual,现在知道的也许只是冰山一角,很多特性还不了解
--写东西要备份,^_^
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值