Database Development Using TDD Chris Oldwood ACCU Conference /
SELECT * FROM Scope Prologue Prologue Principles of TDD Principles of TDD The Public Interface The Public Interface SQL Unit Testing SQL Unit Testing TDD by Example TDD by Example Continuous Integration & Deployment Continuous Integration & Deployment Database Refactoring Database Refactoring Questions Questions
@chrisoldwood is the only person I know with a convincing Agile SQL
Environments SQL based RDBMS SQL based RDBMS Applicable to OLTP & OLAP Applicable to OLTP & OLAP Distributed systems Distributed systems
Principles of TDD Test Driven (Development|Design)
The TDD Cycle Write a failing test (red) Write production code (green) Clean-up code (refactor) Small steps Done (done)
Test-First vs Test-Later Test-first promotes a client-side perspective
Top-Down Design & Implementation Client Services Database Design Implementation Design & Implementation
Executable Specification Helps ensure correctness first Helps ensure correctness first Aids continued correctness after Aids continued correctness after Acts as documentation Acts as documentation
The Public Interface Encapsulation buys you freedom
Public Objects Stored procedures Stored procedures User-defined functions User-defined functions Views Views User-defined types User-defined types
Implementation Details Tables Tables Constraints (triggers) Constraints (triggers) Indexes Indexes
Observable Behaviour Tests should verify the publicly observable behaviour not the choice of implementation
Code Structure Use schemas for partitioning Use schemas for partitioning Embrace composition Embrace composition Single Responsibly Principle Single Responsibly Principle
Performance Encapsulation buys you freedom
SQL Unit Testing
SQL Units Procedure Procedure Function Function View View Legacy (constraints/triggers) Legacy (constraints/triggers)
Development Sandbox Isolation Isolation Fast feedback Fast feedback Deterministic Deterministic Tooling Tooling
SS-Unit Example Test create procedure as -- common arrangement go create procedure as varchar(100) = 'arrangement'; int = 42; int = public.ActOnArrangement(); go exec ssunit.RunTests;
TDD By Example
Example Feature Produce a report showing how many bugs each developer has fixed.
Continuous Integration & Deployment
Continuous (SQL) Integration Build Database Run Test Suite Run Static Analysis
Continuous (System) Integration Build Database Run Unit Tests Build Client Run Unit Tests Build Services Run Unit Tests Run Integration Tests
Continuous Deployment Package Database Run End-to-End Tests Deploy Database Package Services Package Client Deploy ServicesDeploy Client
Developer’s Workstation Development Cycle FeatureWrite testWrite codeRefactor Build Server Build DBUnit TestsInt. Tests System Test Environments PackageDeploySys Tests Done
Database Refactoring
Refactoring Encapsulation buys you freedom
Schema Changes Object names Object names Rationalising data types Rationalising data types Remove dead objects Remove dead objects Table splits/merges Table splits/merges
Questions?
Want to Know More? Bloghttp://chrisoldwood.blogspot.com SS-Unit / SS-Cop / sql2doxygen /