I have read many articles explaining the overview of black- and white-box testing, including this Stack Overflow question: https://stackoverflow.com/questions/7258524/unit-testing-black-box-testing-and-white-box-testing
However I still have some confusion around black-box and white-box testing at a basic level.
In terms of a specific example using Python's
doctest module, I want to know if I am dealing with black- or white-box testing. My code is below.
My guess from what I have read is that this kind of testing is classified as white-box, if I am writing the code as well as the tests. However, what if I were to ask someone else to produce the comment section which produces the tests and then to run the code - would this then be black-box testing?
Perhaps my question is really whether black-box vs white-box categorization is inherent in the code itself, or the context in which the code is run?
The simplicity I am seeking is what to tell as student who is learning about different types of testing whether using
doctest is a white-box or black-box technique or neither or "it depends."
Additionally I would also like to know whether the answer would be the same for the kind of tests present on sites like Hacker Rank and Codewars which look something like
import doctest def fib(n): """ Calculates the n-th Fibonacci number iteratively >>> fib(0) 0 >>> fib(1) 1 >>> fib(10) 55 >>> fib(15) 610 >>> """ a, b = 0, 1 for i in range(n): a, b = b, a + b return a if __name__ == "__main__": doctest.testmod()