software-engineering testing

Definition

Testability

The degree to which a system’s design facilitates the creation and execution of automated tests.

Goal: “Write code with testing in mind.”

Key Concepts

1. Infrastructure vs. Domain

  • Domain: The core business logic (rules, calculations). Should be pure and easy to test.
  • Infrastructure: External dependencies (Database, File System, Network, Time). Hard to test.
  • Strategy: Isolate the domain from the infrastructure.

2. Dependency Injection (DI)

Instead of a class creating its own dependencies (e.g., new Database()), it asks for them in its constructor.

  • Benefit: Allows passing Fake implementations during testing.
  • Pros: Explicit dependencies, separation of concerns, extensibility.

3. Dependency Inversion Principle

High-level modules (Domain) should not depend on low-level modules (Infrastructure). Both should depend on abstractions (Interfaces).

  • Result: The domain doesn’t know what is behind the interface, making it easy to swap a Real Database for a Mock Database.