Running tests in containers in Docker - Time & Space Complexity
When running tests inside Docker containers, it is important to understand how the time taken grows as the number of tests increases.
We want to know how the total test execution time changes when we add more tests to run in containers.
Analyze the time complexity of the following Docker commands used to run multiple tests sequentially.
# Run tests one by one in separate containers
for test_script in test1.sh test2.sh test3.sh; do
docker run --rm -v "$PWD":/app -w /app my-test-image sh "$test_script"
done
This script runs three test scripts one after another, each inside a new Docker container.
Look for repeated actions that affect total time.
- Primary operation: Starting a Docker container and running a test script inside it.
- How many times: Once for each test script in the list.
Each test runs in its own container, so total time adds up with more tests.
| Input Size (n) | Approx. Operations |
|---|---|
| 3 tests | 3 container runs |
| 10 tests | 10 container runs |
| 100 tests | 100 container runs |
Pattern observation: Total time grows directly with the number of tests because each test runs separately.
Time Complexity: O(n)
This means the total time increases in a straight line as you add more tests to run in containers.
[X] Wrong: "Running tests in containers happens all at once, so time stays the same no matter how many tests there are."
[OK] Correct: Each container starts and runs separately, so time adds up with each test unless you run them in parallel.
Understanding how test execution time grows helps you design better test workflows and explain your choices clearly in real projects.
What if we ran all tests in parallel containers instead of one after another? How would the time complexity change?