"Software that is not tested is broken by default."
Overview
In this training you will learn to write well-structured tests for your software projects using the unittest and nose module. After an overview of test frameworks in Python you will implement several test cases, calculate test coverage and learn about the role of tests during refactoring and Test-Driven-Development. After the training, you will be able to write your own tests to build better software in less time.
Objectives
- You will implement a Unit Test, an Acceptance Test and an Integration test (including mock objects & testing in isolation)
- You will implement a new feature by writing a test first.
- You will improve test coverage and refactor the tested code.
Target Audience
This training session is suited for Python developers with little or no prior experience with automated testing.
Training Methodology
The training consists of three rounds of alternating theory and exercises. The theory part includes gamified exercises that help to remember the content, e.g. puzzles and ‘Who wants to be a Millionaire’ questions. During the practical exercises, you will work on a program mining data in Melvilles ‘Moby Dick’. The training is supplemented by a reference PDF including resources for further reading.
Training Structure
Warm-up (10')
- Icebreaker activity (5’)
- Overview: Objectives of the training (5’)
Part 1: Writing automatic tests in Python (45’)
- Warm-up exercise: methods in the unittest module (5’)
- Presentation: Unit Tests, Integration Tests, and Acceptance Tests (15’)
- Exercise: Write one test of each kind (20’)
- Q & A (5’)
Part 2: Test-Driven-Development (45’)
- Warm-up exercise: quiz on test strategies (10’)
- Presentation on Test-Driven-Development (10’)
- Exercise: Write a test first, then implement (20’)
- Q & A (5’)
break (10’)
Part 3: Tests during refactoring (45’)
- Presentation on refactoring strategies (10’)
- Text puzzle: How to calculate test coverage with figleaf (5’)
- Exercise: Combining multiple test modules to a test suite (10’)
- Exercise: Improving test coverage and refactor (15’)
- Q & A (5’)
Summary: Benefits of testing (25’)
- 3-4 Groups discuss a question on benefits of testing (10’)
- Groups present their results (10’)
- Summary & Wrap-up (5’)
Software required
Please install prior to the training
- Python 3.3
- nose
- coverage 3.7+
Integration and Acceptance testing will be done for Python command-line applications using standard modules, so no extra installation is required.