Test-Driven Development in Python
Course objectives
After completing this course you will be able to:
- design object-oriented software for testing - SOLID OOP, Dependency Injection, DI libraries in Python
- write unit tests using mock objects (stub and mock)
- organize tests in a project developed in the TDD methodology
- apply the BDD (Behaviour-Driven Design) approach in cycles - acceptance tests (Behave) and unit tests
- use Python unit testing frameworks and Code-Coverage tools
Course syllabus
Introduction to Test-Driven Development
- Test-Driven Development foundations
- TDD cycle: Red-Green-Refactor
- Inside-out vs. Outside-in TDD
- Pros & cons of TDD
Design a testable code
- SOLID OOP in TDD
- Single-Responsibility Principle
- Open/Close Principle
- Liskov Substitution Principle
- Interface Segregation Principle
- Dependency Inversion Principle
Refactoring patterns
- Removing code duplication
- Extraction of methods and functions
- Extraction of classes
- Replace conditional with polymorphism
- Refactoring towards Design Patterns
Unit tests
- Attributes of good unit tests - FIRST
- Organization of tests in project
- Unit tests frameworks
- unittest
- doctest
- pytest
Unit tests patterns
- Four-Phase Test
- State Verification
- Guard Assertion
- Delta Assertion
- Custom Assertion
- Behavior Verification
Test isolation
- Test doubles - Fake, Dummy, Stub and Mock
- Using Stubs – state verification
- Using Mocks – Behaviour-Based Testing
- unittest.Mock and mockito libraries
- Mock assertions
- Mocking and patching in Python
Integration testing
- Designing and running integration tests
- End-to-End integration testing
BDD - Behaviour-Driven Design
- BDD: "TDD done right"
- Acceptance tests for user stories – the Behave! framework
- Unit tests in BDD
- nose2.Such module
Test coverage
- Code coverage tools
Prerequisites
Attendance of our: - Python Training - Advanced Programming in Python
or equivalent experience with Python