1 / 31

Database Development Using TDD

Database Development Using TDD. Chris Oldwood ACCU Conference 2012. @chrisoldwood / gort@cix.co.uk. SELECT * FROM Scope. Prologue Principles of TDD The Public Interface SQL Unit Testing TDD by Example Continuous Integration & Deployment Database Refactoring Questions.

lynda
Download Presentation

Database Development Using TDD

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Database Development Using TDD Chris Oldwood ACCU Conference 2012 @chrisoldwood / gort@cix.co.uk

  2. SELECT * FROM Scope • Prologue • Principles of TDD • The Public Interface • SQL Unit Testing • TDD by Example • Continuous Integration & Deployment • Database Refactoring • Questions

  3. @chrisoldwood is the only person I know with a convincing Agile SQL story. @allankelly

  4. Environments • SQL based RDBMS • Applicable to OLTP & OLAP • Distributed systems

  5. Principles of TDD Test Driven (Development|Design)

  6. The TDD Cycle Write a failing test (red) Write production code (green) Small steps Clean-up code (refactor) Done (done)

  7. Test-First vs Test-Later Test-first promotes a client-side perspective

  8. Top-Down Design & Implementation Design & Implementation Design Client Services Database Implementation

  9. Executable Specification • Helps ensure correctness first • Aids continued correctness after • Acts as documentation

  10. The Public Interface Encapsulation buys you freedom

  11. Public Objects • Stored procedures • User-defined functions • Views • User-defined types

  12. Implementation Details • Tables • Constraints (triggers) • Indexes

  13. Observable Behaviour Tests should verify the publicly observable behaviour not the choice of implementation

  14. Code Structure • Use schemas for partitioning • Embrace composition • Single Responsibly Principle

  15. Performance Encapsulation buys you freedom

  16. SQL Unit Testing

  17. SQL Units • Procedure • Function • View • Legacy (constraints/triggers)

  18. Development Sandbox • Isolation • Fast feedback • Deterministic • Tooling

  19. SS-Unit Example Test create procedure test._@TestSetUp@_Something as -- common arrangement go create procedure test._@Test@_Something_ShouldDoAnotherThing as declare @arrangement varchar(100) = 'arrangement'; declare @expected int = 42; declare @actual int = public.ActOnArrangement(); exec ssunit.AssertIntegerEqualTo @expected, @actual; go exec ssunit.RunTests;

  20. TDD By Example

  21. Example Feature Produce a report showing how many bugs each developer has fixed.

  22. Continuous Integration & Deployment

  23. Continuous (SQL) Integration Build Database Run Test Suite Run Static Analysis

  24. Continuous (System) Integration Build Database Build Services Build Client Run Unit Tests Run Unit Tests Run Unit Tests Run Integration Tests Run Integration Tests

  25. Continuous Deployment Package Database Package Services Package Client Deploy Database Deploy Services Deploy Client Run End-to-End Tests

  26. Development Cycle Developer’s Workstation Feature Write test Write code Refactor Build Server Build DB Unit Tests Int. Tests System Test Environments Package Deploy Sys Tests Done Done

  27. Database Refactoring

  28. Refactoring Encapsulation buys you freedom

  29. Schema Changes • Object names • Rationalising data types • Remove dead objects • Table splits/merges

  30. Questions?

  31. Want to Know More? Blog http://chrisoldwood.blogspot.com SS-Unit / SS-Cop / sql2doxygen http://www.cix.co.uk/~gort/sql.htm @chrisoldwood / gort@cix.co.uk

More Related