TDD for DB related code

Mikalai Alimenkou
http://xpinjection.com
@xpinjection
Data is very important
What to
test, master?

Everything!
DB testing checklist
O/R mappings
Data flow (incoming and outgoing data)
Stored procedures, functions, triggers
Database s...
Are you
crazy?
Lets talk about techniques
Small quiz: How to test DB code?
Mock direct DB access API
(JDBC in Java)
Mock high level DB access
API (ORM and data acce...
Simplest testing technique

Provide input
data (params +
DB state)

Invoke tested
behavior

Assert
returned value
+ DB sta...
Rollback transactions
We rollback the uncommitted test
transaction as part of the teardown.
Each test is a hero
Each test knows what data is needed
and prepares affected tables.
Constraints and validations
Test suites

Referential integrity

Domain integrity

Main suite
Integration
suite
Validation
...
Database structure management

Incremental updates for all environments
Simple tools
data sets management

integration code and
regular testing DB operations

database management
and versioning
TDD benefits
No need to have checklists
for DB related code

Minimal amount of code
and DB changes
Full control under data...
Show me the code!
@xpinjection
http://xpinjection.com
mikalai.alimenkou@xpinjection.com
TDD for DB integration
Upcoming SlideShare
Loading in...5
×

TDD for DB integration

6,329

Published on

TDD style proved itself as very reliable and quick way of business tasks solving with code. But most of examples on trainings and in the internet show how to apply TDD to simple input/output code or interface based dependencies with mocking techniques. What about other areas of application development like database related code? Could it be developed with TDD style? What does TDD bring to developer? I will try to answer these questions in my talk and show on practical examples how helpful TDD is for database code, how it reduces risks and opens the door for refactoring techniques.

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
6,329
On Slideshare
0
From Embeds
0
Number of Embeds
64
Actions
Shares
0
Downloads
0
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Transcript of "TDD for DB integration"

  1. 1. TDD for DB related code Mikalai Alimenkou http://xpinjection.com @xpinjection
  2. 2. Data is very important
  3. 3. What to test, master? Everything!
  4. 4. DB testing checklist O/R mappings Data flow (incoming and outgoing data) Stored procedures, functions, triggers Database schema View definitions Referential integrity Default values for a column Data invariants for a single column Data invariants involving several columns Database performance
  5. 5. Are you crazy?
  6. 6. Lets talk about techniques
  7. 7. Small quiz: How to test DB code? Mock direct DB access API (JDBC in Java) Mock high level DB access API (ORM and data access frameworks) Mock DB server (SQL level) Test on real DB
  8. 8. Simplest testing technique Provide input data (params + DB state) Invoke tested behavior Assert returned value + DB state
  9. 9. Rollback transactions We rollback the uncommitted test transaction as part of the teardown.
  10. 10. Each test is a hero Each test knows what data is needed and prepares affected tables.
  11. 11. Constraints and validations Test suites Referential integrity Domain integrity Main suite Integration suite Validation suite Each test may manage constraints in runtime
  12. 12. Database structure management Incremental updates for all environments
  13. 13. Simple tools data sets management integration code and regular testing DB operations database management and versioning
  14. 14. TDD benefits No need to have checklists for DB related code Minimal amount of code and DB changes Full control under data access code Open the door for DB refactoring
  15. 15. Show me the code!
  16. 16. @xpinjection http://xpinjection.com mikalai.alimenkou@xpinjection.com

×