Statement Testing is a heuristic to identify new test cases. The existing test suite is analyzed for coverage. If a statement is not covered in the test suite, a new test case can be developed which evaluates this statement. Statement coverage is a stricter form of line coverage.
Consider the OpenZeppelin tryMul function below:
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}This code has the following statements:
a == 0return (true, 0)uint256 c = a * bc / a != breturn (false, 0)return (true, c).
Note that there can be multiple statements per line in the above example (unlike line coverage).
- The
brownieframework provides statement coverage: https://medium.com/coinmonks/brownie-evaluating-solidity-code-coverage-via-opcode-tracing-a7cf5a92d28c