Closed thekid closed 6 years ago
Example:
class CoverageListener implements TestListener {
// ...
public function testRunFinished(TestSuite $suite, TestResult $result) {
$this->coverage->stop();
$result->metric('Coverage', sprintf('▲ %.2f%% lines covered (%d/%d)', ...));
}
}
If we only register a string for printing, there's no way to access the raw value, which we might want to do inside a test run loop, displaying trends.
Maybe like this?
$result->metric('Coverage', new Metric('%.2f%% lines covered (%d/%d)', function() {
$report= $this->coverage->getReport();
$percent= $report->getNumExecutedLines() / $report->getNumExecutableLines() * 100;
return [$percent, $report->getNumExecutedLines(), $report->getNumExecutableLines()];
}));
It would be great if tools like xp-forge/coverage could add statistics to the unittest output, like so:
However, the
testRunFinished()
method of a listener is invoked prior to the statistics being printed. This way, output generated there is printed somewhere inbetween:Maybe the best solution would be to enable listeners to add a statistic to
unittest.TestResult
; which is passed as argument.