Professional Documents
Culture Documents
Test Driven Development
Test Driven Development
Test Driven Development
com
Richard Fennell
Chief Technology Officer (CTO)
MVP (Developer Technologies)
Testing Pyramid
• Scripted Manual Tests
Manual • Exploratory Testing
Test Principles
• Tests should be written at the lowest level possible
• Tests written once, run anywhere including production system
• Product is designed for testability
• Test code is product code, only reliable tests survive
• Testing infrastructure is a shared Service
• Test ownership follows product ownership
+44 1274 300 175 blackmarble.com
Make the
Refactor test
pass
+44 1274 300 175 blackmarble.com
What is Mocking
Stub
Fake
Mock
+44 1274 300 175 blackmarble.com
Data Access Code Logging Code Web Service Code Data Access Code Logging Code Web Service Code
Mocked Mocked Mocked
Mocking Layer(s)
Database Logging Service Web Service
+44 1274 300 175 blackmarble.com
Demo
Mocking with Moq
+44 1274 300 175 blackmarble.com
Pros. Cons.
• Only write code needed • Not a silver bullet
• Easier to maintain/refactor • Can be slow to develop
• High test coverage • Usually needs a lot of mocking
• Tests are the documentation • All the team has to adopt
• Tests must be maintained
+44 1274 300 175 blackmarble.com
Summary
• TDD is a way to get high code coverage
• High code coverage makes refactoring safer
• Mocking is a key tool to enable TDD
• Practice your skills with Coding Katas
+44 1274 300 175 blackmarble.com
Question?
Slides
https://github.com/rfennell/Presentations
+44 1274 300 175 blackmarble.com
Richard Fennell
Chief Technology Officer (CTO)
MVP (Developer Technologies)
blogs.blackmarble.co.uk
@blackmarble
Black Marble