Features :
- 1. small workload
- 2. Test cases are well written
- 3. reusable
- 4. Ease of continuous integration
[u] Walk: [/ u]
- Step 1: Prepare the database
- Step 2: Generate test data template
- Step 3: Prepare test data
- Step 4: Import test data
- Step 5: Prepare Unit Tests
- Step 6: Execute unit tests
Step 1: Prepare the database
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
Step 2: Generate a test data template
that is automatically exported from the database by the tool without any manual action.
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. ##########
Step 3: Prepare test data
Step 4: Import test data
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! ##########
Step 5: Prepare Unit Tests
@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); } }
Step 6: Execute unit tests