Testing shared libraries in Jenkins - Time & Space Complexity
When testing shared libraries in Jenkins, it's important to understand how the time to run tests grows as the library size or number of tests increases.
We want to know how the testing effort scales when more functions or features are added to the shared library.
Analyze the time complexity of the following Jenkins pipeline test code snippet.
def testSharedLibrary() {
def results = []
for (int i = 0; i < testCases.size(); i++) {
results.add(runTest(testCases[i]))
}
return results
}
This code runs a series of tests on each function or feature in the shared library one by one.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Looping through all test cases to run each test.
- How many times: Once for each test case in the list.
As the number of test cases grows, the total time to run all tests grows proportionally.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 test runs |
| 100 | 100 test runs |
| 1000 | 1000 test runs |
Pattern observation: Doubling the number of tests roughly doubles the total work.
Time Complexity: O(n)
This means the testing time grows linearly with the number of test cases.
[X] Wrong: "Running more tests won't affect total time much because tests run fast."
[OK] Correct: Even if each test is quick, running many tests adds up, so total time grows with the number of tests.
Understanding how test time grows helps you plan and optimize testing in real projects, showing you can think about scaling and efficiency.
"What if we ran tests in parallel instead of one by one? How would the time complexity change?"