xp-framework / unittest

Unittests for the XP Framework
0 stars 0 forks source link

Add statistics to result #33

Closed thekid closed 6 years ago

thekid commented 6 years ago

It would be great if tools like xp-forge/coverage could add statistics to the unittest output, like so:

image

However, the testRunFinished() method of a listener is invoked prior to the statistics being printed. This way, output generated there is printed somewhere inbetween:

image

Maybe the best solution would be to enable listeners to add a statistic to unittest.TestResult; which is passed as argument.

thekid commented 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)', ...));
  }
}
thekid commented 6 years ago

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()];
}));
thekid commented 6 years ago

Released in 9.7.0