小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

Junit使用

 看風(fēng)景D人 2014-01-14

單元測(cè)試工具Junit是一個(gè)開源項(xiàng)目

昨天學(xué)習(xí)了一下這個(gè)東西,總結(jié)下心得

1.創(chuàng)建相應(yīng)的test類

package:測(cè)試類存放位置

Name:測(cè)試類名字

setUp,tearDown:測(cè)試類創(chuàng)建測(cè)試環(huán)境以及銷毀測(cè)試環(huán)境,這兩個(gè)方法只執(zhí)行一次

Class Under test:需要被測(cè)試的類路徑及名稱

點(diǎn)擊下一步就會(huì)讓你選擇需要給哪些方法進(jìn)行測(cè)試。

測(cè)試類創(chuàng)建完成后在類中會(huì)出現(xiàn)你選擇的方法的測(cè)試方法:

復(fù)制代碼
 1 package test.com.boco.bomc.alarmrelevance.show.dao;
2
3 import junit.framework.TestCase;
4 import org.junit.After;
5 import org.junit.Before;
6 import org.junit.BeforeClass;
7 import org.junit.Test;
8
9 public class ShowStrategyDaoTest extends TestCase{
10
11 @BeforeClass
12 public static void setUpBeforeClass() throws Exception {
13 System.out.println("OK1");
14 }
15
16 @Before
17 public void setUp() throws Exception {
18 }
19
20 @After
21 public void tearDown() throws Exception {
22 }
23
24 @Test
25 public final void testGetDataByApplyNameOrHostIp() {
26 fail("Not yet implemented"); // TODO
27 }
28
29 @Test
30 public final void testGetDataByObject() {
31 fail("Not yet implemented"); // TODO
32 }
33
34 @Test(timeout=1)
35 public final void testGetApplyUser() {
36 fail("Not yet implemented"); // TODO
37 }
38
39 @Test
40 public final void testGetVoiceUser() {
41 fail("Not yet implemented"); // TODO
42 }
43
44 @Test
45 public final void testSearchInAera() {
46 fail("Not yet implemented"); // TODO
47 }
48
49 @Test
50 public final void testGetDataByPolicyId() {
51 fail("Not yet implemented"); // TODO
52 }
53
54 }
復(fù)制代碼

其中的@before,@test,@after表示在執(zhí)行測(cè)試方法前執(zhí)行,需執(zhí)行的測(cè)試方法,在測(cè)試方法執(zhí)行后執(zhí)行

可以給@test添加timeout,exception參數(shù)

在測(cè)試方法中可以用assertEquals(arg0,arg1);

可以用TestSuite把多個(gè)測(cè)試類集中到一起,統(tǒng)一執(zhí)行測(cè)試,例如:

復(fù)制代碼
 1 package test.com.boco.bomc.alarmrelevance.show.dao;
2
3 import junit.framework.Test;
4 import junit.framework.TestSuite;
5
6
7 public class TestAll {
8 public static Test suite(){
9 TestSuite suite = new TestSuite("Running all the tests");
10 suite.addTestSuite(ShowStrategyDaoTest.class);
11 suite.addTestSuite(com.boco.bomc.alarmrelevance.show.dao.ShowStrategyDaoTest.class);
12 return suite;
13 }
14 }
復(fù)制代碼

另外還可以把多個(gè)TestSuite組合到一個(gè)Test類里面,例如:

復(fù)制代碼
 1 package test.com.boco.bomc.alarmrelevance.show.dao;
2
3 import junit.framework.Test;
4 import junit.framework.TestCase;
5 import junit.framework.TestSuite;
6
7 public class TestAll1 extends TestCase {
8 public static Test suite(){
9 TestSuite suite1 = new TestSuite("TestAll1");
10 suite1.addTest(TestAll.suite());
11 suite1.addTest(TestAll2.suite());
12 return suite1;
13 }
14 }
復(fù)制代碼

這就更方便與集中測(cè)試,一個(gè)方法測(cè)試完了,可以對(duì)個(gè)方法,多個(gè)類一起測(cè)試

注意:在寫代碼的時(shí)候TestSuite,TestCase,Test的包不要到錯(cuò)了

測(cè)試效果如下:

                                       ----->froest

My cnblogs is :

http://www.cnblogs.com/God-froest/

Welcome you to exchange technology with me.

《夜的鋼琴曲八》

                              ---石進(jìn)

Piano music can develop the temperament of a man.



 

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購(gòu)買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多