CPA Testing, Debugging & Code Optimization 2 ā Questions and Answers
Question 1: Which testing approach tests the internal logic and structure of the code rather than just its external behavior?
- Black-box testing
- White-box testing (Correct answer)
- Regression testing
- Acceptance testing
Correct answer: White-box testing
White-box testing examines the internal code structure, branches, and paths, unlike black-box testing which only evaluates inputs and outputs.
Question 2: What is a 'breakpoint' in the context of debugging?
- A line where the program crashes
- A marker that pauses execution so the developer can inspect state (Correct answer)
- A syntax error in the code
- A test that intentionally fails
Correct answer: A marker that pauses execution so the developer can inspect state
A breakpoint is a deliberate stopping point set by the developer in a debugger to pause program execution and examine variables and flow.
Question 3: Which metric measures the percentage of source code lines executed during testing?
- Cyclomatic complexity
- Code coverage (Correct answer)
- Defect density
- Test velocity
Correct answer: Code coverage
Code coverage (specifically line coverage) reports what percentage of code lines were executed by the test suite.
Question 4: What is the purpose of a stub in unit testing?
- To generate random test data
- To replace a real dependency with a minimal controlled implementation (Correct answer)
- To measure execution time of a function
- To document test cases
Correct answer: To replace a real dependency with a minimal controlled implementation
A stub replaces a real dependency (like a database or API) with a simple controlled version so the unit under test can run in isolation.
Question 5: Which optimization technique moves a loop-invariant computation outside of the loop?
- Loop unrolling
- Loop hoisting (code motion) (Correct answer)
- Memoization
- Dead code elimination
Correct answer: Loop hoisting (code motion)
Loop hoisting (also called loop-invariant code motion) moves calculations whose result does not change across iterations outside the loop to avoid redundant work.
Question 6: What does 'regression testing' primarily verify?
- New features work correctly
- Previously working functionality has not been broken by recent changes (Correct answer)
- Code meets performance benchmarks
- Security vulnerabilities are absent
Correct answer: Previously working functionality has not been broken by recent changes
Regression testing re-runs existing tests after code changes to confirm that previously working behavior has not been inadvertently broken.
Question 7: In big-O notation, which complexity grows most slowly as input size increases?
- O(n)
- O(log n) (Correct answer)
- O(n log n)
- O(n²)
Correct answer: O(log n)
O(log n) grows much more slowly than linear O(n) time, making logarithmic algorithms highly efficient for large inputs.
Which testing approach tests the internal logic and structure of the code rather than just its external behavior?