日期:2014-05-16 浏览次数:20408 次
// dbo.users 的测试案例 testDBOUsers = { // 测试案例的名称 name: function() { return "DBO Users Test"; }, // 每次执行测试方法之前都进行数据清理和初始化 // 清空测试数据库并插入新数据 setUp: function() { clear(); init(); }, // 每次执行测试方法之前都进行数据清理 // 清空测试数据库 tearDown: function() { clear(); }, // 测试 init 方法,略 testInit: function() { ... }, // 测试 dbo.users.list() 方法,逐一验证返回结果 testList: function() { var users = dbo.users.list(); Assert.assertEquals(2, users.length, 0); Assert.assertEquals("user1", users[0].name); Assert.assertEquals("desc1", users[0].desc); Assert.assertEquals("user2", users[1].name); Assert.assertEquals("desc2", users[1].desc); }, // 测试 dbo.users.save(...) 方法,验证 users 集合的变化 testSaveAsAdd: function() { dbo.users.save({ name: 'xxx', desc: 'yyy' }); var users = getUsers(); Assert.assertEquals(3, users.length, 0); Assert.assertEquals("xxx", users[2].name); Assert.assertEquals("yyy", users[2].desc); }, // 以下省略 };
testDBO = { name: function() { return "DBO Test"; }, suite: function() { return [ testDBOUsers ]; } };
testPage = { name: function() { return "Page Test"; }, setUp: function() { clear(); init(); }, tearDown: function() { clear(); }, testIndex: function() { var ret = page.index(); var users = getUsers(); Assert.assertTrue(ret.indexOf(users[0].name) >= 0); Assert.assertTrue(ret.indexOf(users[0].desc) >= 0); Assert.assertTrue(ret.indexOf(users[1].name) >= 0); Assert.assertTrue(ret.indexOf(users[1].desc) >= 0); } };
testAPIUsers = { name: function() { return "API Users Test"; }, setUp: function() { clear(); init(); }, tearDown: function() { clear(); }, testSave: function() { api.users.save({ name: 'xxx', desc: 'yyy' }); var users = getUsers(); Assert.assertEquals(3, users.length, 0); Assert.assertEquals("xxx", users[2].name); Assert.assertEquals("yyy", users[2].desc); }, testRemove: function() { api.users.remove("user1"); var users = getUsers(); Assert.assertEquals(1, users.length, 0); Assert.assertEquals("user2", users[0].name); Assert.assertEquals("desc2", users[0].desc); }, testExists: function() { Assert.assertTrue(dbo.users.exists("user1"))