皇家方舟

          junit assert() 使用實(shí)例

          package com.liyingcheng.netTest;


          import com.liyingcheng.net.Sort;

          import junit.framework.Test;
          import junit.framework.TestCase;
          import junit.framework.TestSuite;
          import junit.xiaoxuhui.Sum;


          public class SortTest extends TestCase
          {
          ?// Sort popObj = new Sort();

          ?public SortTest(String name)
          ?{
          ??super(name);
          ?}


          ?protected void setUp() throws Exception
          ?{
          ??super.setUp();
          ?}


          ?protected void tearDown() throws Exception
          ?{
          ??super.tearDown();
          ?}


          ?static public void assertEquals(int[] expected, int[] actual)
          ?{
          ??for(int i = 0; i < expected.length; i++)
          ??{
          ???assertEquals(null, expected[i], actual[i]);
          ??}
          ?}


          ?public void testPopSort()
          ?{
          ??int[] expected = new int[] {1, 2, 3, 4};
          ??assertEquals(expected, Sort.popSort(new int[] {1, 2, 4, 3}));
          ??assertEquals(expected, Sort.popSort(new int[] {1, 2, 3, 4}));
          ??assertEquals(expected, Sort.popSort(new int[] {1, 3, 4, 2}));
          ??assertEquals(expected, Sort.popSort(new int[] {1, 3, 2, 4}));
          ??assertEquals(expected, Sort.popSort(new int[] {2, 1, 4, 3}));
          ??assertEquals(expected, Sort.popSort(new int[] {2, 4, 1, 3}));
          ??assertEquals(expected, Sort.popSort(new int[] {3, 2, 4, 1}));
          ??assertEquals(new int[] {1, 2}, Sort.popSort(new int[] {2, 1}));
          ??// assertEquals(new int[]{1,3,2,4},popObj.popSort(new int[]{1,2,4,3}));
          ??// assertEquals(new int[]{1,2,3,4},popObj.popSort(new int[]{1,2,4,3}));
          ?}


          ?public void testCreateArray()
          ?{
          ??assertEquals(4, Sort.createArray(4).length);
          ?}


          ?public void testGetSum()
          ?{
          ??assertEquals(5050, Sum.getSum(1, 100));
          ?}


          ?public void testFalse()
          ?{
          ??assertFalse(false);
          ??assertTrue(true);
          ?}


          ?public void testIsNull()
          ?{
          ??String str1 = "";
          ??int[] arr1 = {};
          ??String str2 = null;
          ??int[] arr2 = null;
          ??assertNotNull(str1);
          ??assertNotNull(arr1);
          ??assertNull(str2);
          ??assertNull(arr2);
          ??// assertNull(str);
          ?}


          ?public void testNull()
          ?{
          ?}


          ?public void testNotSame()
          ?{
          ??String str1 = "123";
          ??String str2 = "123";
          ??String str3 = new String(str1);
          ??String str4 = new String("123");
          ??int one = 1;
          ??int first = 1;
          ??assertSame(one, first);
          ??assertSame(str1, str2);
          ??assertNotSame(str3, str4);
          ??//fail("hahahahahahahah");
          ??/*
          ?? * assertNotSame(one,first); assertNotSame(str1,str2);
          ?? */
          ?}


          ?public static Test suite()
          ?{
          ??TestSuite suite = new TestSuite("Test sort!");
          ??suite.addTestSuite(SortTest.class);
          ??return suite;
          ?}

          }



          posted on 2006-09-19 15:13 阿輝 閱讀(1380) 評(píng)論(1)  編輯  收藏 所屬分類: junit

          Feedback

          # assertEquals與assertSame的區(qū)別 2006-09-19 17:27 阿輝

          http://www.51testing.com/cgi-bin/archiver/?tid-13165.html  回復(fù)  更多評(píng)論   


          My Links

          Blog Stats

          常用鏈接

          留言簿(1)

          隨筆分類

          隨筆檔案

          搜索

          積分與排名

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          主站蜘蛛池模板: 黄石市| 湘潭县| 江华| 治多县| 英德市| 德江县| 内丘县| 金湖县| 鄂托克前旗| 扎兰屯市| 金门县| 东宁县| 霍山县| 鹰潭市| 托里县| 资兴市| 宁乡县| 突泉县| 安岳县| 新野县| 聂拉木县| 夏津县| 河西区| 彭州市| 旬邑县| 汉沽区| 新郑市| 乌鲁木齐县| 疏附县| 青田县| 元阳县| 兰西县| 南乐县| 双辽市| 方山县| 盐边县| 富顺县| 孝昌县| 建阳市| 夏邑县| 凤城市|