posts - 32,comments - 8,trackbacks - 0

          reference:
          http://dev.yesky.com/275/2132275.shtml

          1.在eclipse新建一個java project

          2.新建一個class: hello, package = example, 代碼如下:

          package example;

          public class hello
          {
           
          public int abs(int n)
           {
            
          return n >= 0 ? n : (-n);
           }
          }


          3.右鍵點擊hello.java,選擇:new - junit test case
          setUp / tearDown打鉤, 最下方click here點擊,添加JUnit.jar文件 - next

          4.選擇abs()方法

          5.修改Hellotest代碼:

          package example;

          import junit.framework.TestCase;

          public class helloTest extends TestCase
          {
              
          private hello _hello;

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

                  _hello 
          = new hello();
              }

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

              
          public void testAbs()
              {
                  assertEquals(_hello.abs(
          14), 14);
                  assertEquals(_hello.abs(
          -5), 5);
                  assertEquals(_hello.abs(
          0), 0);
              }
          }


          6. 運行


          posted on 2008-12-03 15:38 張辰 閱讀(133) 評論(0)  編輯  收藏

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 延津县| 石阡县| 陆丰市| 沅江市| 金沙县| 囊谦县| 竹北市| 灵丘县| 深水埗区| 灵石县| 吉木萨尔县| 平果县| 嘉兴市| 河西区| 确山县| 沁阳市| 澄城县| 湛江市| 盘山县| 汕头市| 呼玛县| 临夏县| 佛坪县| 泰州市| 梓潼县| 乌审旗| 平谷区| 夏津县| 镇雄县| 兴安盟| 靖安县| 永福县| 高要市| 小金县| 武鸣县| 远安县| 中牟县| 东至县| 定远县| 温泉县| 利津县|