基于轻量级容器架构DAO层可重复性单元测试  被引量:1

Repeatability Unit Testing about DAO Layer Based on Lightweight Container Architecture

在线阅读下载全文

作  者:张珂良[1] 薛莉芳[2] 

机构地区:[1]东华大学计算机科学与技术学院,上海200051 [2]上海万达信息股份有限公司,上海201112

出  处:《计算机技术与发展》2009年第5期33-36,共4页Computer Technology and Development

基  金:上海市政府电子政务项目(WD-GDRSJ0701)

摘  要:单元测试的出现给程序员的编程工作带来了乐趣,更多的程序员希望能进行深入实践。但在对单元测试更加全面深入的使用过程中,却遇到了越来越多的障碍。随着B/S架构的流行,轻量级容器架构的J2EE模式是大多数项目的首选,并在此基础上使用DAO(数据访问对象)模式与数据库层进行交互。数据库中的数据会在使用过程中变得不稳定,会使得测试代码变得不具可重复性。而单元测试最重要的特性就是可重复性,文中探讨的就是关于DAO层的单元测试的可重复性。经过在实际项目中的认真实践得出了可行的方法,现作简要介绍。DAO层的单元测试的依赖于数据库中的数据,实现单元测试的可重复性需要对于每次单元测试执行时数据库的数据都是符合要求的。可从两方面保证数据库中的数据符合要求:一是启动每轮单元测试时提供符合要求的数据;二是对于那些会破坏数据库状态的单元测试在结束时均执行一个恢复操作,将数据库恢复到原来的状态。Unit testing brings programmer's development fun. So more programmers want to practice it deeply. However, they counter more and more difficulties when they use unit testing deeply. Along with the fashion of B/S architecture,J2EE with lightweight container architecture is the first choice for many projects. And DAO (Data Access Object) pattern is used to communicate with database layer. The data in database will become unstable in the proceas of using the data and therefore makes test code can not become repetitive. But repeatability is the most important feature in unit testing. This paper is about the repeatability of the unit testing on the DAO layer. After the seriously practice of practical project come to a viable way, will describle it completely, here is a briefing. The unit test of DAO layer depends on the data in the database, to achieve repeatability of the unit test requires for the implementation of each time when testing data are in line with the requirements. Can ensure that the data in the database to meet the requirements from two aspects: First, provide data to meet the requirements when start each round of unit test. Second, for those unit test which would undermine the state of database,at the end of the test all execute a resumption of operation, then the database will return to original state.

关 键 词:单元测试 可重复性 测试驱动开发 JUNIT 

分 类 号:TP311.5[自动化与计算机技术—计算机软件与理论]

 

参考文献:

正在载入数据...

 

二级参考文献:

正在载入数据...

 

耦合文献:

正在载入数据...

 

引证文献:

正在载入数据...

 

二级引证文献:

正在载入数据...

 

同被引文献:

正在载入数据...

 

相关期刊文献:

正在载入数据...

相关的主题
相关的作者对象
相关的机构对象