You can use hooks to get information about scenarios, including their tags, however you can only do this in @beforeFeature
or @beforeSuite
.
Unfortunately this means it will not report on scenarios with tags that are being filtered out.
Here is my initial solution.
class Context extends BehatContext {
protected static $scenarioCount = 0;
protected static $scenarioCountWip = 0;
/**
* Count scenarios and WIP
* @BeforeScenario
*/
public function countScenario(Behat\Behat\Event\ScenarioEvent $scenario)
{
self::$scenarioCount++;
if(in_array('wip', $scenario->getScenario()->getTags())) {
self::$scenarioCountWip++;
}
}
/**
* @AfterSuite
*/
public static function coverageReport()
{
echo 'Scenarios: '.self::$scenarioCount.PHP_EOL;
echo ' - in progress: '.self::$scenarioCountWip.PHP_EOL;
echo ' - coverage: '.(100/self::$scenarioCount)*(self::$scenarioCount-self::$scenarioCountWip).PHP_EOL;
echo PHP_EOL;
}
}
The feature file:
Feature: Test Count
@wip
Scenario: Work in progress
@someTag
Scenario: Scenarion with tag
Scenario: Final scenario
The result when running all tests:
Feature: Test Count
@wip
Scenario: Work in progress
@someTag
Scenario: Scenarion with tag
Scenario: Final scenario
Scenarios: 3
- in progress: 1
- coverage: 66.666666666667
3 scenarios (3 passed)
No steps
This the result whit @wip filtered out:
Feature: Test Count
@someTag
Scenario: Scenarion with tag
Scenario: Final scenario
Scenarios: 2
- in progress: 0
- coverage: 100
2 scenarios (2 passed)
No steps
I'll leave the question open in the hope someone finds a better solution.