liveBook · Manning

Open-box testing

As explained in Learn AI-Assisted Python Programming, Second Edition

Open-box testing is a software-testing technique that examines a program's implementation to identify likely failures and design structure-specific tests.

Open-box testing examines a program’s implementation to find likely failure points and design tests tailored to its structure. Unlike closed-box testing, it uses both the function specification and the code, while still varying inputs and checking expected results. section 6.2 section 6.2.3

Use the code as a source of test ideas:

  • Inspect conditions for boundary mistakes, such as using >= when > is required. section 6.2.3
  • Trace loops and test their first element, last element, empty input, and other edge cases. section 6.2.3
  • Combine structure-specific tests with closed-box tests to strengthen coverage. section 6.2

Finding a hidden longest-word error

Suppose longest_word should return the first word when several words tie for maximum length. Reading its loop reveals the condition len(words[i]) >= len(longest). Testing ['cat', 'dog', 'me'] exposes the error: the function returns 'dog' instead of 'cat'. Changing >= to > preserves the first longest word. The same code inspection also suggests testing an empty list and lists whose relevant word appears first or last. section 6.2.3

Table 6.1 Brief overview of closed-box and open-box testing
Closed-box testing
Open-box testing
Requires understanding the function specification to test
Requires both the function specification and the code that implements the function to test
Tests don’t require an understanding of what the code does.
Tests should be tailored based on how the code was written.
Testers need not have technical expertise about the code they’re testing.
Testers need to be able to understand the code sufficiently well to determine which tests may be more important.
Tests the function by varying inputs and checking against expected results
Can test the function in the same way as closed-box testing but can also have more granular tests within a function

Compare the information, expertise, and test granularity required by closed-box and open-box testing. section 6.2

How Learn AI-Assisted Python Programming, Second Edition covers it

How deep it goes
Examines conditions and loops for likely failures, then stops at designing focused tests rather than formal implementation analysis.
Examples
Uses an incorrect longest_word comparison, loop-boundary cases, traffic-data cases, doctests, and find_max coverage exercises.
What it assumes
Assumes a function specification and enough implementation knowledge to identify important code paths and likely edge cases.
What you can do after
Diagnose/debug with it by reading code, predicting failure points, and writing tests for uncovered boundaries and branches.
How it connects
Connects open-box testing with closed-box testing, edge cases, test coverage, and doctest.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn AI-Assisted Python Programming, Second Edition. The section links point to the parts of the book it draws on.