Develop practical unit and component testing capability across C/C++, Python and Rust, progressing from language-specific test frameworks into memory and thread-safety analysis, mocking, property-based testing and cross-language test architecture.
This eight-hour module combines hands-on testing with wider test-strategy thinking. Participants work with GoogleTest, Catch2, pytest and cargo test, explore test doubles and property-based testing, and use specialist tools to identify memory, concurrency and undefined-behaviour issues.
The module then connects those individual language workflows through contract testing, shared test data and a documented test strategy for a polyglot software system.
View the Full Software Testing & Verification Programme
What You Will Learn
Module 3 moves from the static-analysis techniques introduced in Module 2 into executable testing of software components.
Participants develop practical workflows for testing C/C++, Python and Rust software while also learning how to reason about test architecture across language boundaries.
By the end of the module, participants will have worked with unit-test frameworks, fixtures, parametrisation, mocking, property-based testing, memory and thread-safety tools, async testing and cross-language contracts.
The module also introduces the test pyramid, consumer-driven contract testing, shared test data and ownership models so that individual unit tests can form part of a coherent wider verification strategy.
Topics
C/C++
- GoogleTest and Catch2 frameworks; fixtures and parameterized tests
- Test doubles: stubs, fakes, mocks and spies
- Memory and thread safety: Valgrind, AddressSanitizer, UndefinedBehaviorSanitizer, ThreadSanitizer
Python
- pytest: fixtures, scope, parametrization and markers
- Mocking with unittest.mock
- Property-based testing with hypothesis; async tests with pytest-asyncio
Rust
- cargo test: organisation, attributes and doc tests
- Property-based testing with proptest and shrinking
- Undefined-behaviour detection with Miri; mocking with mockall
- Async tests with tokio::test; benchmarking with criterion.rs
Test Strategy & Cross-Language Architecture
- The test pyramid and the inverted-pyramid anti-pattern
- Contract testing and consumer-driven contracts
- Cross-language mocking and shared test data
- Test strategy documentation and ownership models
Lab 1: C/C++ Unit Testing & Memory Safety
Learning Objectives: GoogleTest, Catch2, Valgrind, AddressSanitizer, ThreadSanitizer
Description: Write a GoogleTest suite for a sample component and validate it for memory and thread safety.
Tasks
- Write a GoogleTest suite using TEST and a fixture with SetUp/TearDown.
- Write an equivalent Catch2 test using TEST_CASE and SECTION.
- Run the suite under Valgrind and resolve one reported memory leak.
- Run the suite under AddressSanitizer and resolve one heap error.
- Write a small multithreaded test and run it under ThreadSanitizer.
- Identify two test doubles (a stub and a mock) needed for the component’s dependencies.
Extension Tasks
- Add a GoogleTest parameterized test covering three input sets.
- Add a Catch2 BDD-style Given/When/Then test.
Topics Covered
GoogleTest, Catch2, Valgrind, AddressSanitizer, ThreadSanitizer, Test Doubles
Open Source Recommendation
GoogleTest, Catch2, Valgrind, and LLVM’s AddressSanitizer/ThreadSanitizer: all open-source.
Lab 2: Python Testing with pytest & Mocking
Learning Objectives: pytest, fixtures, unittest.mock, hypothesis
Description: Build a pytest suite for a sample module with fixtures, mocking and a property-based test.
Tasks
- Write pytest tests using fixtures at function and module scope.
- Parametrize one test across at least three input sets.
- Mock an external API call using unittest.mock.patch.
- Assert an expected exception using pytest.raises.
- Write a hypothesis property-based test for a pure function.
- Configure a shared conftest.py fixture used by two test files.
Extension Tasks
- Add a pytest-asyncio test for an async function.
- Add a pytest marker to skip a platform-specific test.
Topics Covered
pytest, Fixtures, Mocking, hypothesis
Open Source Recommendation
pytest with its pytest-mock/pytest-asyncio plugins, and the hypothesis property-based testing library.
Lab 3: Rust Testing with cargo test & proptest
Learning Objectives: cargo test, proptest, Miri, mockall
Description: Write a cargo test suite for a sample crate, add a property-based test, and check an unsafe function under Miri.
Tasks
- Write unit tests using
#[test]andassert_eq!/assert!. - Organise tests into an in-module unit suite and a
tests/integration suite. - Write a proptest property test using the
proptest!macro. - Interpret a proptest shrinking result for a failing case.
- Run a sample unsafe function under
cargo +nightly miri test. - Mock a trait dependency using mockall.
Extension Tasks
- Add a
#[tokio::test]for an async function. - Add a criterion.rs benchmark for one function.
Topics Covered
cargo test, proptest, Miri, mockall
Open Source Recommendation
cargo test (built into Rust), proptest, Miri and mockall: all open-source Rust crates.
Lab 4: Cross-Language Test Architecture & Contracts
Learning Objectives: Test pyramid, contract testing, cross-language mocking, shared test data
Description: Design a test architecture for a small polyglot system spanning the three languages tested in Labs 1–3.
Tasks
- Map the sample system’s components onto a test pyramid (unit/integration/E2E ratios).
- Define a consumer-driven contract between a Python client and a Rust service.
- Design a mock/stub approach for calling the C/C++ component from a Python test.
- Build one shared test data fixture reused across two language-specific suites.
- Draft a one-page test strategy document section for the polyglot system.
- Identify one risk of over-mocking at a cross-language integration boundary.
Extension Tasks
- Propose a versioning approach for the shared test fixture.
- Draft ownership assignment for each language’s test suite.
Topics Covered
Test Pyramid, Contract Testing, Cross-Language Mocking, Test Strategy Documentation
Open Source Recommendation
Pact, an open-source consumer-driven contract testing framework, for the cross-language contract exercise.
Module 3 Coverage Matrix
| Topic | Lab 1 | Lab 2 | Lab 3 | Lab 4 |
|---|---|---|---|---|
| C/C++ Unit Testing | ✓ | ✓ | ||
| Python Unit Testing | ✓ | ✓ | ||
| Rust Unit Testing | ✓ | ✓ | ||
| Memory & Thread Safety Tools | ✓ | |||
| Property-Based Testing | ✓ | ✓ | ||
| Test Architecture & Strategy | ✓ |
Module Project: Polyglot Component Test Suite
Polyglot component test suite: deliver GoogleTest/Catch2, pytest and cargo test suites for a shared sample system’s three language-specific components, with a documented test strategy and one cross-language contract test.
The module project brings the individual language-specific laboratories into one integrated verification exercise.
Rather than treating C/C++, Python and Rust testing as separate activities, participants organise the resulting suites around a shared software system and document how those tests fit together across component boundaries.
The resulting project provides practical evidence of:
language-specific testing → component verification → shared test architecture → cross-language contract testing
Why Unit and Component Testing Matter Within the Programme
Static analysis can expose many classes of defects without executing software, but executable tests are needed to check behaviour against expected results.
Module 3 therefore moves the programme from:
Static Analysis → Unit Testing → Component Verification
Participants learn how to test isolated behaviours while managing external dependencies, memory behaviour, asynchronous functions and cross-language interfaces.
This becomes important preparation for Module 4: Structural Code Coverage & MC/DC, where attention shifts from whether tests pass to how thoroughly those tests exercise the implementation.
From Static Analysis to Executable Verification
Module 3 directly follows Module 2: Static Analysis & Code Quality.
Module 2 identifies potential issues through source-level analysis.
Module 3 tests executable behaviour.
The relationship should be presented clearly on the site:
Module 2
Static Analysis & Code Quality
↓
Module 3
Unit & Component Testing
↓
Module 4
Structural Code Coverage & MC/DC
This progression is particularly valuable for the programme architecture because each page owns a different technical search intent rather than competing for the same keywords.
How Module 3 Connects With Later Modules
The techniques introduced here form practical inputs into several later areas of the programme.
Structural Code Coverage & MC/DC builds upon executable test suites to measure what has actually been exercised.
Integration & Protocol-Level Testing extends the scope beyond individual components and into interactions between services, protocols and data layers.
Test Automation & CI/CD Integration later automates GoogleTest/Catch2, pytest and cargo test in a multi-language pipeline.
Frequently Asked Questions
Which programming languages are covered in the Unit & Component Testing module?
The module covers C/C++, Python and Rust, with dedicated practical testing workflows for each language.
Which C/C++ testing frameworks are covered?
Participants work with GoogleTest and Catch2 and use fixtures, parameterized tests and test doubles. The C/C++ lab also introduces Valgrind, AddressSanitizer and ThreadSanitizer for memory and concurrency validation.
What Python testing tools are used?
The Python section uses pytest, unittest.mock and hypothesis. It also introduces pytest-asyncio and shared fixtures through conftest.py.
How is Rust testing covered?
Participants use cargo test, proptest, Miri and mockall. Extension work also introduces tokio::test and criterion.rs.
Does this module cover mocking and test doubles?
Yes. The module covers stubs, fakes, mocks and spies, together with practical dependency mocking in the C/C++, Python and Rust workflows.
Is property-based testing included?
Yes. Python property-based testing uses hypothesis, while Rust uses proptest and its shrinking behaviour.
Does the module cover memory and thread-safety testing?
Yes. The C/C++ laboratory includes Valgrind, AddressSanitizer and ThreadSanitizer.
What is cross-language contract testing?
The module introduces consumer-driven contracts and asks participants to define a contract between a Python client and a Rust service. Pact is recommended for the cross-language contract exercise.
What is the Module 3 project?
The project is a Polyglot Component Test Suite combining GoogleTest/Catch2, pytest and cargo test suites for three language-specific components, with a documented test strategy and one cross-language contract test.
