Skip to content

Commit

Permalink
Add support for BDD tests (.feature) (#1034)
Browse files Browse the repository at this point in the history
* Add BDD testsuite (.feature) support

* Refactor .feature code
  • Loading branch information
edno committed Feb 6, 2020
1 parent 1d79de5 commit 96c6a3f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/TestFramework/Coverage/JUnitTestFileDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ public function getTestFileInfo(string $fullyQualifiedClassName): TestFileTimeDa
$nodes = $xPath->query(sprintf('//testcase[@class="%s"]', $fullyQualifiedClassName));
}

if (!$nodes->length) {
$feature = preg_replace('/^(.*):+.*$/', '$1.feature', $fullyQualifiedClassName);
// try another format where the class name is inside `file` attribute of `testcase` tag
$nodes = $xPath->query(sprintf('//testcase[contains(@file, "%s")]', $feature));
}

if (!$nodes->length) {
throw TestFileNameNotFoundException::notFoundFromFQN($fullyQualifiedClassName, $this->jUnitFilePath);
}
Expand Down
9 changes: 9 additions & 0 deletions tests/phpunit/Fixtures/Files/phpunit/junit_feature.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite name="acceptance" tests="4" assertions="11" errors="0" failures="0" skipped="0" time="0.604773">
<testcase file="/codeception/tests/bdd/FeatureA.feature" name="Feature A: Scenario A1" assertions="6" time="0.039365"/>
<testcase file="/codeception/tests/bdd/FeatureB.feature" name="Feature B: Scenario B2" assertions="2" time="0.022857"/>
<testcase file="/codeception/tests/bdd/FeatureA.feature" name="Feature A: Scenario A2" assertions="1" time="0.029354"/>
<testcase file="/codeception/tests/bdd/FeatureA.feature" name="Feature A: Scenario A3" assertions="2" time="0.025091"/>
</testsuite>
</testsuites>
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,15 @@ public function test_it_works_with_different_junit_format(): void

$this->assertSame('/codeception/tests/unit/SourceClassTest.php', $info1->path);
}

public function test_it_works_with_feature_junit_format(): void
{
$provider = new JUnitTestFileDataProvider(
__DIR__ . '/../../Fixtures/Files/phpunit/junit_feature.xml'
);

$testFileInfo = $provider->getTestFileInfo('FeatureA:Scenario A1');

$this->assertSame('/codeception/tests/bdd/FeatureA.feature', $testFileInfo->path);
}
}

0 comments on commit 96c6a3f

Please sign in to comment.