vjame

优化代码是无止境的
随笔 - 65, 文章 - 9, 评论 - 26, 引用 - 0
数据加载中……

Junit.3.8.详解

import junit.framework.Assert;
import junit.framework.TestCase;

import com.test.Largest;

public class TestLargest extends TestCase {

    Largest l;

    @Override
    
protected void setUp() throws Exception {
        l 
= new Largest();
    }

    
public void testGetL() {
        
int[] array = { 23456734578222999 };
        
int result = 0;
        ;
        
try {
            result 
= l.getLargest(array);

        } 
catch (Exception e) {
            
// TODO Auto-generated catch block
            e.printStackTrace();
        }
        Assert.assertEquals(
999, result);
    }

    
public void testGetL2() {
        
int[] array = {};

        Throwable tx 
= null;
        
try {
            l.getLargest(array);
            Assert.fail();
        } 
catch (Exception ex) {
            tx 
= ex;
        }

        Assert.assertNotNull(tx);
        Assert.assertEquals(Exception.
class, tx.getClass());
        Assert.assertEquals(
"数组不能为空!", tx.getMessage());

    }

    
public void testGetL3() {
        Throwable tx 
= null;
        
try {
            
int[] array = null;

            l.getLargest(array);
            Assert.fail();
        } 
catch (Exception ex) {
            tx 
= ex;
        }
        Assert.assertNotNull(tx);
        Assert.assertEquals(Exception.
class, tx.getClass());
        Assert.assertEquals(
"数组不能为空!", tx.getMessage());
    }
}

posted on 2009-01-20 12:01 lanjh 阅读(242) 评论(0)  编辑  收藏


只有注册用户登录后才能发表评论。


网站导航: