posts - 32,comments - 8,trackbacks - 0

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

          1.在eclipse新建一個(gè)java project

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

          package example;

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


          3.右鍵點(diǎn)擊hello.java,選擇:new - junit test case
          setUp / tearDown打鉤, 最下方click here點(diǎn)擊,添加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. 運(yùn)行


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

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 黔南| 泊头市| 柏乡县| 扎赉特旗| 清涧县| 翁源县| 绍兴县| 湟源县| 博罗县| 文安县| 常州市| 澄城县| 大名县| 通辽市| 朝阳县| 甘孜| 宁夏| 渑池县| 谷城县| 濮阳县| 化州市| 东阳市| 宣化县| 马公市| 遂平县| 北宁市| 柯坪县| 江门市| 本溪市| 富顺县| 鸡泽县| 时尚| 全椒县| 三台县| 陈巴尔虎旗| 临安市| 酉阳| 门源| 抚远县| 黄大仙区| 喀喇|