Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Test Driven Development with SQL

27 views

Published on

Why SQL to explain TDD: SQL is a language that is being easily understood by almost every developer in this world. Hence selected SQL to explain the benefit of using TDD.

This presentation will be about benefits of TDD and SQL code is used as examples.

Agile Design

In Agile Development, Design is supposed to be built gradually as per the need. But if your software is huge and complex, you can never have the confidence to build as per need, unless using TDD.

Code Refactor

In your complex applications, if you do not use TDD and do frequent refactoring then be ready for disastrous consequences of failed dependencies and failure of previously working components.

Test Automation

TDD is of great help for Test Automation. In summary, TDD helps continuous delivery of Quality code with high productivity.

Published in: Leadership & Management
  • Be the first to comment

Test Driven Development with SQL

  1. 1. TEST DRIVEN DEVELOPMENT WITH SQL Prakash Aryal 1st – 3rd December, 2017 | Westin, Hyderabad, INDIA
  2. 2. Test Driven Development Testing, a short Story!
  3. 3. Agile Principles • Our highest priority is to satisfy the customer through early and continuous delivery of valuable software.
  4. 4. Agile Principles • Welcome changing requirements, even late in development. Agile processes harness change for the customer's competitive advantage.
  5. 5. Agile Principles • Deliver working software frequently, from a couple of weeks to a couple of months, with a preference to the shorter timescale.
  6. 6. Agile Principles • Working software is the primary measure of progress.
  7. 7. Agile Principles • Agile processes promote sustainable development. The sponsors, developers, and users should be able to maintain a constant pace indefinitely.
  8. 8. Agile Principles • Our highest priority is to satisfy the customer through early and continuous delivery of valuable software. • Welcome changing requirements, even late in development. Agile processes harness change for the customer's competitive advantage. • Deliver working software frequently, from a couple of weeks to a couple of months, with a preference to the shorter timescale. • Working software is the primary measure of progress. • Agile processes promote sustainable development. The sponsors, developers, and users should be able to maintain a constant pace indefinitely.
  9. 9. Test Driven Development Take out Test Driven Development and it is impossible to achieve these Agile Principles!!
  10. 10. Test Driven Development - Steps
  11. 11. Quality Working Software is difficult without TDD
  12. 12. Without TDD – Refactoring is very risky!
  13. 13. Without TDD – Agile Design is impossible!
  14. 14. Test Driven Development – Steps(Recap)
  15. 15. Example (Existing Query and Report) SELECT e.employee_id, e.last_name, d.department_name FROM (SELECT * FROM employees) e JOIN departments d ON (e.department_id = d.department_id);
  16. 16. Requirement Add DOB column and Report with updated DOB for Employee ID = 149 Fields to be reported: • Employee ID • Employee Name(Last Name) • DOB • Department Name
  17. 17. Add a test case and expect it to Fail SELECT CASE WHEN COUNT(*) = 1 THEN 'PASS' ELSE 'FAIL' END result FROM USER_TAB_COLUMNS WHERE TABLE_NAME = 'EMPLOYEES' AND COLUMN_NAME = 'DOB'; RESULT ------- FAIL
  18. 18. Update the code, so it passes the new test ALTER TABLE employees ADD dob DATE;
  19. 19. Verify if the test case Passes SELECT CASE WHEN COUNT(*) = 1 THEN 'PASS' ELSE 'FAIL' END result FROM USER_TAB_COLUMNS WHERE TABLE_NAME = 'EMPLOYEES' AND COLUMN_NAME = 'DOB'; RESULT ------- PASS
  20. 20. 1ST Test Case Ends.. (Refactored Query) SELECT e.employee_id, e.last_name, e.department_id, d.department_name, To_Char(e.dob, 'dd-Month-yyyy') dob FROM employees e JOIN departments d ON (e.department_id = d.department_id);
  21. 21. Add 2nd test case and expect it to Fail SELECT CASE WHEN COUNT(*) = 1 THEN 'PASS' ELSE 'FAIL' END result FROM employees WHERE employee_id = 149 AND dob IS NOT NULL; RESULT ------- FAIL
  22. 22. Update the code, so it passes the 2nd test UPDATE employees SET dob = TO_DATE('12-FEB-1995', 'DD-MON-YYYY') WHERE employee_id = 149; COMMIT;
  23. 23. Verify if the 2nd test case Passes SELECT CASE WHEN COUNT(*) = 1 THEN 'PASS' ELSE 'FAIL' END result FROM employees WHERE employee_id = 149 AND dob IS NOT NULL; RESULT ------- PASS
  24. 24. Final Query and Report SELECT e.employee_id, e.last_name, e.department_id, d.department_name, To_Char(e.dob, 'dd-Month-yyyy') dob FROM employees e JOIN departments d ON (e.department_id = d.department_id);
  25. 25. Test Driven Development Discussion Time!
  26. 26. Prakash Aryal Principal Engineer 977-9847470183 prakasharyal1@gmail.com verscend.com Thank You

×