Download presentation
Presentation is loading. Please wait.
Published bySamantha Willis Modified over 9 years ago
1
Database Development Using TDD Chris Oldwood ACCU Conference 2012 @chrisoldwood / gort@cix.co.uk
2
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
3
@chrisoldwood is the only person I know with a convincing Agile SQL story. @allankelly
4
Environments SQL based RDBMS SQL based RDBMS Applicable to OLTP & OLAP Applicable to OLTP & OLAP Distributed systems Distributed systems
5
Principles of TDD Test Driven (Development|Design)
6
The TDD Cycle Write a failing test (red) Write production code (green) Clean-up code (refactor) Small steps Done (done)
7
Test-First vs Test-Later Test-first promotes a client-side perspective
8
Top-Down Design & Implementation Client Services Database Design Implementation Design & Implementation
9
Executable Specification Helps ensure correctness first Helps ensure correctness first Aids continued correctness after Aids continued correctness after Acts as documentation Acts as documentation
10
The Public Interface Encapsulation buys you freedom
11
Public Objects Stored procedures Stored procedures User-defined functions User-defined functions Views Views User-defined types User-defined types
12
Implementation Details Tables Tables Constraints (triggers) Constraints (triggers) Indexes Indexes
13
Observable Behaviour Tests should verify the publicly observable behaviour not the choice of implementation
14
Code Structure Use schemas for partitioning Use schemas for partitioning Embrace composition Embrace composition Single Responsibly Principle Single Responsibly Principle
15
Performance Encapsulation buys you freedom
16
SQL Unit Testing
17
SQL Units Procedure Procedure Function Function View View Legacy (constraints/triggers) Legacy (constraints/triggers)
18
Development Sandbox Isolation Isolation Fast feedback Fast feedback Deterministic Deterministic Tooling 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 Run Unit Tests Build Client Run Unit Tests Build Services Run Unit Tests Run Integration Tests
25
Continuous Deployment Package Database Run End-to-End Tests Deploy Database Package Services Package Client Deploy ServicesDeploy Client
26
Developer’s Workstation Development Cycle FeatureWrite testWrite codeRefactor Build Server Build DBUnit TestsInt. Tests System Test Environments PackageDeploySys Tests Done
27
Database Refactoring
28
Refactoring Encapsulation buys you freedom
29
Schema Changes Object names Object names Rationalising data types Rationalising data types Remove dead objects Remove dead objects Table splits/merges Table splits/merges
30
Questions?
31
Want to Know More? Bloghttp://chrisoldwood.blogspot.com SS-Unit / SS-Cop / sql2doxygen http://www.cix.co.uk/~gort/sql.htm @chrisoldwood / gort@cix.co.uk
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.