免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 848 | 回复: 0
打印 上一主题 下一主题

JUnit in java 真正的测试用例实战(2) [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-03-05 15:27 |只看该作者 |倒序浏览

可能对于一个测试类中有多个方法要测试,对于后面看着的确有些困难,因此,我对上测试类进行简单的调整,如下代码:

file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image011.gif
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image011.gif
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image011.gif
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image011.gif
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image011.gif
import junit.framework.TestCase;
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image011.gif
import junit.textui.TestRunner;
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image011.gif
import com.zhjy.mock.SpringMock;
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image011.gif
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image007.gif
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image008.gif
/** *//**
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
* 举例测试类
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image010.gif
*/
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image007.gif
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image008.gif
public class OrgTypeDAOTest extends TestCase ...{    //(1)继承TestCase
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
    //private OrgTypeDAO orgTypeDAO;
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
    //private OrgTypeVO orgTypeVO;
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
    //private String id ;
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image012.gif
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image013.gif
    /** *//**
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
     *  构造方法
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
     * @param arg0
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image014.gif
     */
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image012.gif
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image013.gif
    public OrgTypeDAOTest(String arg0) ...{
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        super(arg0);
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image014.gif
    }   
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image012.gif
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image013.gif
    /**//* 初时化方法
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
     * @see junit.framework.TestCase#setUp()
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image014.gif
     */
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image012.gif
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image013.gif
    protected void setUp() throws Exception ...{
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        super.setUp();
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        //测试初始话数据调用类 orgTypeDAO和 封装数据的对象orgTypeVO
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image014.gif
    }
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image012.gif
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image013.gif
    /**//* 执行完清理方法
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
     * @see junit.framework.TestCase#tearDown()
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image014.gif
     */
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image012.gif
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image013.gif
    protected void tearDown() throws Exception ...{
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        //清空 对象  ;==null
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        //orgTypeDAO =null;
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        //orgTypeVO =null;
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        super.tearDown();
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image014.gif
    }
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image012.gif
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image013.gif
    /** *//**
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
     *  主函数
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
     * @param args
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image014.gif
     */
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image012.gif
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image013.gif
    public static void main(String[] args)...{
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        TestRunner.run(OrgTypeDAOTest.class);
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image014.gif
    }
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image012.gif
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image013.gif
    /** *//**
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
     * 测试方法
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
     * Test method testOrgTypeInfo
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image014.gif
     */
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image012.gif
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image013.gif
    public void testOrgTypeInfo() ...{
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        //添加
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        String id = insertOrgTypeInfo();
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        //列表
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        orgTypeList();
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        //修改
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        updateOrgTypeInfo(id);
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        //查询
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        selectOrgTypeInfoById(id);
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        //校验
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        iExistOrgByOrgTypeId(id);
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        //测试是否重复数据方法(add)
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        isRepeatOrgTypeInfo(orgTypeVO.getName(),"");
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        //获取数据方法(根据名称)
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        selectOrgTypeIdByName(orgTypeVO.getName());
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        //删除
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        deleteOrgTypeInfo(id);
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image014.gif
    }
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image012.gif
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image013.gif
    /**//*
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
     *添加初始数据
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image014.gif
     */
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image012.gif
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image013.gif
    private void setOrgTypeVOAddInfo() ...{
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        orgTypeVO.setName("add中海测试");
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        orgTypeVO.setDescription("add中海测试");
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        orgTypeVO.setStatus("1");
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image014.gif
    }
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image012.gif
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image013.gif
    /**//*
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
     *添加初始数据
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image014.gif
     */
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image012.gif
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image013.gif
    private void setOrgTypeVOUpdateInfo() ...{
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        //orgTypeVO.setId(id);
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        orgTypeVO.setName("add中海测试");
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        orgTypeVO.setDescription("update中海测试");
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        orgTypeVO.setStatus("1");
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image014.gif
    }
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image012.gif
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image013.gif
    /**//*
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
     * 新增方法
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
     * Test method for {@link OrgTypeDAO#insertOrgTypeInfo(com.zhjy.mltx.vo.OrgTypeVO)}.
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image014.gif
     */
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image012.gif
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image013.gif
    public String insertOrgTypeInfo() ...{
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        setOrgTypeVOAddInfo();
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        String id = null;
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image012.gif
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image013.gif
        try...{
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
            id = orgTypeDAO.insertOrgTypeInfo(orgTypeVO);
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image012.gif
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image013.gif
        }catch(Exception e)...{
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
            fail("添加通用组织机构失败!");
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image014.gif
        }
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        return id;
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image014.gif
    }
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image012.gif
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image013.gif
    /**//*
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
     * 更新方法
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
     * Test method for {@link com.zhjy.mltx.dao.OrgTypeDAO#updateOrgTypeInfo(com.zhjy.mltx.vo.OrgTypeVO)}.
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image014.gif
     */
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image012.gif
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image013.gif
    public void updateOrgTypeInfo(String id) ...{
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        setOrgTypeVOUpdateInfo();
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        orgTypeVO.setId(id);
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image012.gif
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image013.gif
        try...{
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
            orgTypeDAO.updateOrgTypeInfo(orgTypeVO);
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image012.gif
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image013.gif
        }catch(Exception e)...{
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
            assertTrue("修改通用组织机构失败!", false);
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image014.gif
        }
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        //查询
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        orgTypeVO = orgTypeDAO.selectOrgTypeInfoById(id);
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        assertEquals("修改通用组织机构失败!", orgTypeVO.getDescription(), "update中海测试");
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image014.gif
    }
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image012.gif
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image013.gif
    /**//*
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
     * 获取数据方法(主健)
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
     * Test method for {@link OrgTypeDAO#selectOrgTypeInfoById(java.lang.String)}.
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image014.gif
     */
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image012.gif
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image013.gif
    public void selectOrgTypeInfoById(String id) ...{
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        orgTypeVO = orgTypeDAO.selectOrgTypeInfoById(id);
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        assertTrue("无法查看一条通用机构名称信息!",orgTypeVO != null);
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        assertEquals("添加通用组织机构失败!", orgTypeVO.getName(), "add中海测试");
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        assertEquals("修改通用组织机构失败!", orgTypeVO.getDescription(), "update中海测试");
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image014.gif
    }
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image012.gif
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image013.gif
    /**//*
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
     * 测试此通用组织机构是否被引用
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
     * Test method for {@link OrgTypeDAO#iExistOrgByOrgTypeId(java.lang.String)}.
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image014.gif
     */
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image012.gif
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image013.gif
    public void iExistOrgByOrgTypeId(String id) ...{
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        boolean isfalse;
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image012.gif
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image013.gif
        try ...{
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
            isfalse = this.orgTypeDAO.iExistOrgByOrgTypeId(id);
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
            assertFalse("通用组织机构校验错误!",isfalse);
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image012.gif
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image013.gif
        } catch (DataAccessException e) ...{
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
            assertTrue("通用组织机构数据操作错误!!",false);
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image012.gif
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image013.gif
        } catch (ObjectNotFoundException e) ...{
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
            assertTrue("id is null!!",false);
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image014.gif
        }
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image014.gif
    }
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image012.gif
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image013.gif
    /**//*
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
     * 删除
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
     * Test method for {@link OrgTypeDAO#deleteOrgTypeInfo(java.lang.String)}.
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image014.gif
     */
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image012.gif
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image013.gif
    public void deleteOrgTypeInfo(String id) ...{
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        this.orgTypeDAO.deleteOrgTypeInfo(id);
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        orgTypeVO = this.orgTypeDAO.selectOrgTypeInfoById(id);
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        assertNull("删除通用组织机构失败!", orgTypeVO);
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image014.gif
    }
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image012.gif
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image013.gif
    /**//*
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
     * 获取数据方法(根据名称)
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
     * Test method for {@link OrgTypeDAO#selectOrgTypeIdByName(java.lang.String)}.
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image014.gif
     */
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image012.gif
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image013.gif
    public void selectOrgTypeIdByName(String name) ...{
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        String orgtypeid = orgTypeDAO.selectOrgTypeIdByName(name);
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        //assertEquals(orgtypeid, id);
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        assertNotNull("未查出来通用组织机构ID!",orgtypeid);
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image014.gif
    }
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image012.gif
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image013.gif
    /**//*
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
     * 测试是否重复数据方法
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
     * Test method for {@link OrgTypeDAO#isRepeatOrgTypeInfo(com.zhjy.mltx.vo.OrgTypeVO)}.
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image014.gif
     */
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image012.gif
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image013.gif
    public void isRepeatOrgTypeInfo(String name,String id) ...{
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        //setOrgTypeVOUpdateInfo();
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        OrgTypeVO orgtypetest = new OrgTypeVO();
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        orgtypetest.setId(id);
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        orgtypetest.setName(name);
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        boolean isTrue = orgTypeDAO.isRepeatOrgTypeInfo(orgtypetest);
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        //assertEquals("通用组织机构错误数据",isTrue, false);
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        assertTrue("通用组织机构错误数据", isTrue);
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image014.gif
    }
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image012.gif
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image013.gif
    /**//*
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
     * 列表方法
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
     * Test method for {@link com.zhjy.mltx.dao.OrgTypeDAO#orgTypeList()}.
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image014.gif
     */
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image012.gif
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image013.gif
    public void orgTypeList() ...{
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        List list = orgTypeDAO.orgTypeList();
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
        assertNotNull("无法获取通用机构名称列表list is null!",list);
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image014.gif
    }
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image009.gif
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image010.gif
}
file:///C:/DOCUME~1/ADMINI~1/LOCALS~1/Temp/msohtmlclip1/02/clip_image011.gif


处理过程:
1)把所有以test开头的方法中的方法名称前的test去掉(例如把testOrgTypeList()改为orgTypeList()方法);
2)同时添加一个以test开头的方法,并调用测试方法;这样做主要是因为执行测试时JUnit(除本身特有的方法出外)只执行以test为开头的方法;
3)同时大家注意到我还把测试初始数据放到两个private方法中private void setOrgTypeVOAddInfo()private void setOrgTypeVOUpdateInfo()方法中供调用;

        大家可能认为很简单,就是这样简单的改动带来很大的方便,大家是否注意到,我以后运行测试用例时,只关心public void testOrgTypeInfo() 方法就行了,因为只要各个方法的断言策略定制完成,一般就不会再改动,因此,后期的回归测试还是验收测试,缩小了我们对测试的关注点,同时对后面写 test suite构建整体测试带来极大方便性!其中的好处相信只有使用才能体会!

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/19726/showart_253480.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP