论坛首页 Java企业应用论坛

数据驱动测试(二) – 实例

浏览 3429 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2014-03-16   最后修改:2014-03-16
数据驱动测试(二) – 实例

特点:
  • 1. 工作量小
  • 2. 测试案例很好写
  • 3. 可重复利用
  • 4. 便于持续集成

步骤:
  • 步骤一:准备数据库
  • 步骤二:生成测试数据模板
  • 步骤三:准备测试数据
  • 步骤四:导入测试数据
  • 步骤五:准备单元测试
  • 步骤六:执行单元测试

步骤一:准备数据库
INFO -- ERD ==> DDTT_BOOK
INFO -- ERD ==> DDTT_CLASS
INFO -- ERD ==> 	|-DDTT_STUDENT_CLASS
INFO -- ERD ==> DDTT_SCHOOL
INFO -- ERD ==> 	|-DDTT_STUDENT
INFO -- ERD ==> 		|-DDTT_STUDENT_CLASS

步骤二:生成测试数据模板
由工具自动从数据库中导出,无需任何手工动作。
INFO -- ########## Start to sync table structure ##########
INFO -- D:\research\ddt\dev\bin\test-data-config.properties is loaded from absolute path.

INFO -- ########## Configurations ##########
INFO -- Excel version: 2007
INFO -- Tables and versions: all
INFO -- Processed tables: DDTT_, XXX_
INFO -- Ignored tables: XXX_\S*|YYY_\S*
INFO -- Process child tables: true
INFO -- Disable triggers: false
INFO -- ########## Configurations ##########

INFO -- Test Data: D:\research\ddt\dev\DDT_TEST_DATA.xlsx
INFO -- Load tables from database to memory

INFO -- =========== Start to load tables ... ===========
INFO -- Load meta data for table: DDTT_BOOK [1/5]
INFO -- Load meta data for table: DDTT_CLASS [2/5]
INFO -- Load meta data for table: DDTT_SCHOOL [3/5]
INFO -- Load meta data for table: DDTT_STUDENT [4/5]
INFO -- Load meta data for table: DDTT_STUDENT_CLASS [5/5]
INFO -- =========== End to load tables ===========

INFO -- =========== Start to sync all tables ... ===========
INFO -- To sync the sheet DDTT_BOOK
INFO -- To sync the sheet DDTT_CLASS
INFO -- To sync the sheet DDTT_SCHOOL
INFO -- To sync the sheet DDTT_STUDENT
INFO -- To sync the sheet DDTT_STUDENT_CLASS
INFO -- =========== End to sync all tables ===========

INFO -- All test data cells are protected, password is 'password'
INFO -- Updating the Master Config sheet ...
INFO -- ########## Table structure is sync successfully. ##########

步骤三:准备测试数据

步骤四:导入测试数据
INFO -- ########## Start to sync test data ##########
INFO -- D:\research\ddt\dev\bin\test-data-config.properties is loaded from absolute path.

INFO -- ########## Configurations ##########
INFO -- Excel version: 2007
INFO -- Tables and versions: all
INFO -- Processed tables: DDTT_, XXX_
INFO -- Ignored tables: XXX_\S*|YYY_\S*
INFO -- Process child tables: true
INFO -- Disable triggers: false
INFO -- ########## Configurations ##########

INFO -- Test Data: D:\research\ddt\dev\DDT_TEST_DATA.xlsx

INFO -- =========== Start to get records ==========
INFO -- Get record list of sheet=DDTT_BOOK, version=all
INFO -- Get record list of sheet=DDTT_CLASS, version=all
INFO -- Get record list of sheet=DDTT_SCHOOL, version=all
INFO -- Get record list of sheet=DDTT_STUDENT, version=all
INFO -- Get record list of sheet=DDTT_STUDENT_CLASS, version=all
INFO -- =========== Get records successfully ==========

INFO -- =========== Start to clear records ==========
INFO -- Clear DDTT_BOOK starts.
INFO -- Clear DDTT_BOOK finished. 3 record(s) are deleted.
INFO -- Clear DDTT_CLASS starts.
INFO -- Clear DDTT_STUDENT_CLASS starts.
INFO -- Clear DDTT_STUDENT_CLASS finished. 2 record(s) are deleted.
INFO -- Clear DDTT_CLASS finished. 2 record(s) are deleted.
INFO -- Clear DDTT_SCHOOL starts.
INFO -- Clear DDTT_STUDENT starts.
INFO -- Clear DDTT_STUDENT finished. 2 record(s) are deleted.
INFO -- Clear DDTT_SCHOOL finished. 2 record(s) are deleted.
INFO -- =========== Clear records successfully ==========

INFO -- =========== Start to insert records ==========
INFO -- Insert DDTT_BOOK starts.
INFO -- Insert DDTT_BOOK finished. 3 record(s) are inserted.
INFO -- Insert DDTT_CLASS starts.
INFO -- Insert DDTT_CLASS finished. 2 record(s) are inserted.
INFO -- Insert DDTT_SCHOOL starts.
INFO -- Insert DDTT_SCHOOL finished. 2 record(s) are inserted.
INFO -- Insert DDTT_STUDENT_CLASS starts.
INFO -- Insert DDTT_STUDENT starts.
INFO -- Insert DDTT_STUDENT finished. 2 record(s) are inserted.
INFO -- Insert DDTT_STUDENT_CLASS finished. 2 record(s) are inserted.
INFO -- =========== Insert records successfully ==========

INFO -- ########## Test data is sync successfully! ##########

步骤五:准备单元测试
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:bean-ddtt-test.xml")
public class StudentServiceTest extends AbstractTransactionalJUnit4SpringContextTests {
	
	@Resource
	private StudentService studentService;

	@Test
	//DDTT v0.001
	public void findStudentTest() {
		//this case will find a issue: RowMapper doesn't work for no record found case
		StudentTO to = studentService.findStudent(1234567890);
		Assert.assertNull(to);
		
		to = studentService.findStudent(1);
		Assert.assertNotNull(to);
		Assert.assertEquals(to.getName(), "Jason");
	}
	
	@Test
	//DDTT v0.002
	public void deleteStudentTest() {
		studentService.deleteStudent(2);
		
		StudentTO to = studentService.findStudent(2);
		Assert.assertNull(to);
	}

}

步骤六:执行单元测试


  • 大小: 23.2 KB
  • 大小: 20.1 KB
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics