Skip to content

Commit bf2143d

Browse files
authored
MQE-1372: If Suite before fails build must be RED
- Added testIncomplete override to allure adapter, will mark incomplete tests as failed - Lifted runFailed functionality from extension into TestContextExtension to be able to write incomplete tests to the failed fail - Removed runFailed exception from etc version of Codeception.yml
1 parent d5265e9 commit bf2143d

File tree

5 files changed

+69
-4
lines changed

5 files changed

+69
-4
lines changed

dev/tests/verification/Resources/functionalSuiteHooks.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class functionalSuiteHooks extends \Codeception\GroupObject
3030

3131
if ($this->preconditionFailure != null) {
3232
//if our preconditions fail, we need to mark all the tests as incomplete.
33-
$e->getTest()->getMetadata()->setIncomplete($this->preconditionFailure);
33+
$e->getTest()->getMetadata()->setIncomplete("SUITE PRECONDITION FAILED:" . PHP_EOL . $this->preconditionFailure);
3434
}
3535
}
3636

etc/config/codeception.dist.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ settings:
1212
memory_limit: 1024M
1313
extensions:
1414
enabled:
15-
- Codeception\Extension\RunFailed
1615
- Magento\FunctionalTestingFramework\Extension\TestContextExtension
1716
- Magento\FunctionalTestingFramework\Allure\Adapter\MagentoAllureAdapter
1817
config:

src/Magento/FunctionalTestingFramework/Allure/Adapter/MagentoAllureAdapter.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
use Yandex\Allure\Adapter\Event\StepStartedEvent;
1111
use Yandex\Allure\Adapter\Event\StepFinishedEvent;
1212
use Yandex\Allure\Adapter\Event\StepFailedEvent;
13+
use Yandex\Allure\Adapter\Event\TestCaseFailedEvent;
14+
use Codeception\Event\FailEvent;
1315
use Codeception\Event\SuiteEvent;
1416
use Codeception\Event\StepEvent;
1517

@@ -132,4 +134,18 @@ public function stepAfter(StepEvent $stepEvent = null)
132134
}
133135
$this->getLifecycle()->fire(new StepFinishedEvent());
134136
}
137+
138+
/**
139+
* Override of parent method, fires a TestCaseFailedEvent if a test is marked as incomplete.
140+
*
141+
* @param FailEvent $failEvent
142+
* @return void
143+
*/
144+
public function testIncomplete(FailEvent $failEvent)
145+
{
146+
$event = new TestCaseFailedEvent();
147+
$e = $failEvent->getFail();
148+
$message = $e->getMessage();
149+
$this->getLifecycle()->fire($event->withException($e)->withMessage($message));
150+
}
135151
}

src/Magento/FunctionalTestingFramework/Extension/TestContextExtension.php

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
class TestContextExtension extends BaseExtension
1717
{
1818
const TEST_PHASE_AFTER = "_after";
19+
const TEST_FAILED_FILE = 'failed';
1920

2021
/**
2122
* Codeception Events Mapping to methods
@@ -35,7 +36,8 @@ public function _initialize()
3536
Events::TEST_START => 'testStart',
3637
Events::TEST_FAIL => 'testFail',
3738
Events::STEP_AFTER => 'afterStep',
38-
Events::TEST_END => 'testEnd'
39+
Events::TEST_END => 'testEnd',
40+
Events::RESULT_PRINT_AFTER => 'saveFailed'
3941
];
4042
self::$events = array_merge(parent::$events, $events);
4143
parent::_initialize();
@@ -170,4 +172,52 @@ public function afterStep(\Codeception\Event\StepEvent $e)
170172
{
171173
ErrorLogger::getInstance()->logErrors($this->getDriver(), $e);
172174
}
175+
176+
/**
177+
* Saves failed tests from last codecept run command into a file in _output directory
178+
* Removes file if there were no failures in last run command
179+
* @param \Codeception\Event\PrintResultEvent $e
180+
* @return void
181+
*/
182+
public function saveFailed(\Codeception\Event\PrintResultEvent $e)
183+
{
184+
$file = $this->getLogDir() . self::TEST_FAILED_FILE;
185+
$result = $e->getResult();
186+
$output = [];
187+
188+
// Remove previous file regardless if we're writing a new file
189+
if (is_file($file)) {
190+
unlink($file);
191+
}
192+
193+
foreach ($result->failures() as $fail) {
194+
$output[] = $this->localizePath(\Codeception\Test\Descriptor::getTestFullName($fail->failedTest()));
195+
}
196+
foreach ($result->errors() as $fail) {
197+
$output[] = $this->localizePath(\Codeception\Test\Descriptor::getTestFullName($fail->failedTest()));
198+
}
199+
foreach ($result->notImplemented() as $fail) {
200+
$output[] = $this->localizePath(\Codeception\Test\Descriptor::getTestFullName($fail->failedTest()));
201+
}
202+
203+
if (empty($output)) {
204+
return;
205+
}
206+
207+
file_put_contents($file, implode("\n", $output));
208+
}
209+
210+
/**
211+
* Returns localized path to string, for writing failed file.
212+
* @param string $path
213+
* @return string
214+
*/
215+
protected function localizePath($path)
216+
{
217+
$root = realpath($this->getRootDir()) . DIRECTORY_SEPARATOR;
218+
if (substr($path, 0, strlen($root)) == $root) {
219+
return substr($path, strlen($root));
220+
}
221+
return $path;
222+
}
173223
}

src/Magento/FunctionalTestingFramework/Suite/views/SuiteClass.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class {{suiteName}} extends \Codeception\GroupObject
3131
3232
if ($this->preconditionFailure != null) {
3333
//if our preconditions fail, we need to mark all the tests as incomplete.
34-
$e->getTest()->getMetadata()->setIncomplete($this->preconditionFailure);
34+
$e->getTest()->getMetadata()->setIncomplete("SUITE PRECONDITION FAILED:" . PHP_EOL . $this->preconditionFailure);
3535
}
3636
}
3737

0 commit comments

Comments
 (0)