Skip to content

Commit 59d131f

Browse files
authored
Merge pull request #22 from magento-commerce/MQE-2463
MQE-2463: Mftf test extends from a skipped parent should be skipped
2 parents 7f0cf87 + fa57a42 commit 59d131f

File tree

5 files changed

+80
-33
lines changed

5 files changed

+80
-33
lines changed

dev/tests/unit/Magento/FunctionalTestFramework/Test/Util/ObjectExtensionUtilTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,41 @@ public function testExtendingExtendedActionGroup()
346346
}
347347
}
348348

349+
/**
350+
* Tests generating a test that extends a skipped parent test
351+
*
352+
* @throws \Exception
353+
*/
354+
public function testExtendedTestSkippedParent()
355+
{
356+
$testDataArrayBuilder = new TestDataArrayBuilder();
357+
$mockParentTest = $testDataArrayBuilder
358+
->withName('baseTest')
359+
->withAnnotations([
360+
'skip' => ['nodeName' => 'skip', 'issueId' => [['nodeName' => 'issueId', 'value' => 'someIssue']]]
361+
])
362+
->build();
363+
364+
$testDataArrayBuilder->reset();
365+
$mockExtendedTest = $testDataArrayBuilder
366+
->withName('extendTest')
367+
->withTestReference("baseTest")
368+
->build();
369+
370+
$mockTestData = array_merge($mockParentTest, $mockExtendedTest);
371+
$this->setMockTestOutput($mockTestData);
372+
373+
// parse and generate test object with mocked data
374+
TestObjectHandler::getInstance()->getObject('extendTest');
375+
376+
// validate log statement
377+
TestLoggingUtil::getInstance()->validateMockLogStatement(
378+
'debug',
379+
"extendTest is skipped due to ParentTestIsSkipped",
380+
[]
381+
);
382+
}
383+
349384
/**
350385
* Function used to set mock for parser return and force init method to run between tests.
351386
*

dev/tests/unit/Util/TestDataArrayBuilder.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,28 @@ public function withTestReference($reference = null)
232232
return $this;
233233
}
234234

235+
/**
236+
* Reset data array builder
237+
*
238+
* @return void
239+
*/
240+
public function reset()
241+
{
242+
// reset
243+
$this->testName = 'testTest';
244+
$this->filename = null;
245+
$this->testActionBeforeName = 'testActionBefore';
246+
$this->testActionAfterName = 'testActionAfter';
247+
$this->testActionFailedName = 'testActionFailed';
248+
$this->testActionType = 'testAction';
249+
$this->annotations = [];
250+
$this->beforeHook = [];
251+
$this->afterHook = [];
252+
$this->failedHook = [];
253+
$this->testReference = null;
254+
$this->testActions = [];
255+
}
256+
235257
/**
236258
* Output the resulting test data array based on parameters set in the object
237259
*

dev/tests/verification/Resources/ExtendingSkippedTest.txt

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,33 +19,6 @@ use Yandex\Allure\Adapter\Annotation\TestCaseId;
1919
*/
2020
class ExtendingSkippedTestCest
2121
{
22-
/**
23-
* @param AcceptanceTester $I
24-
* @throws \Exception
25-
*/
26-
public function _before(AcceptanceTester $I)
27-
{
28-
$I->amOnPage("/beforeUrl"); // stepKey: beforeAmOnPageKey
29-
}
30-
31-
/**
32-
* @param AcceptanceTester $I
33-
* @throws \Exception
34-
*/
35-
public function _after(AcceptanceTester $I)
36-
{
37-
$I->amOnPage("/afterUrl"); // stepKey: afterAmOnPageKey
38-
}
39-
40-
/**
41-
* @param AcceptanceTester $I
42-
* @throws \Exception
43-
*/
44-
public function _failed(AcceptanceTester $I)
45-
{
46-
$I->saveScreenshot(); // stepKey: saveScreenshot
47-
}
48-
4922
/**
5023
* @Severity(level = SeverityLevel::CRITICAL)
5124
* @Features({"TestModule"})
@@ -55,9 +28,8 @@ class ExtendingSkippedTestCest
5528
* @return void
5629
* @throws \Exception
5730
*/
58-
public function ExtendingSkippedTest(AcceptanceTester $I)
31+
public function ExtendingSkippedTest(AcceptanceTester $I, \Codeception\Scenario $scenario)
5932
{
60-
$I->comment("text");
61-
$I->comment("child");
33+
$scenario->skip("This test is skipped due to the following issues:\nParentTestIsSkipped");
6234
}
6335
}

docs/extending.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ Specify needed variations for a parent object and produce a copy of the original
1515
Unlike merging, the parent test (or action group) will still exist after the test generation.
1616
</div>
1717

18+
<div class="bs-callout-warning" markdown="1">
19+
<br>
20+
Note: The extended test will be skipped if the parent test is skipped.
21+
</div>
22+
1823
## Extending tests
1924

2025
### Update a test step

src/Magento/FunctionalTestingFramework/Test/Util/ObjectExtensionUtil.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ public function extendTest($testObject)
4242
try {
4343
$parentTest = TestObjectHandler::getInstance()->getObject($testObject->getParentName());
4444
} catch (TestReferenceException $error) {
45+
$skippedTest = $this->skipTest($testObject, 'ParentTestDoesNotExist');
4546
if (MftfApplicationConfig::getConfig()->verboseEnabled()) {
4647
LoggingUtil::getInstance()->getLogger(ObjectExtensionUtil::class)->debug(
4748
"parent test not defined. test will be skipped",
4849
["parent" => $testObject->getParentName(), "test" => $testObject->getName()]
4950
);
5051
}
51-
$skippedTest = $this->skipTest($testObject);
5252
return $skippedTest;
5353
}
5454

@@ -64,6 +64,11 @@ public function extendTest($testObject)
6464
->debug("extending test", ["parent" => $parentTest->getName(), "test" => $testObject->getName()]);
6565
}
6666

67+
// Skip test if parent is skipped
68+
if ($parentTest->isSkipped()) {
69+
return $this->skipTest($testObject);
70+
}
71+
6772
// Get steps for both the parent and the child tests
6873
$referencedTestSteps = $parentTest->getUnresolvedSteps();
6974
$newSteps = $this->processRemoveActions(array_merge($referencedTestSteps, $testObject->getUnresolvedSteps()));
@@ -207,17 +212,19 @@ private function processRemoveActions($actions)
207212
* This method returns a skipped form of the Test Object
208213
*
209214
* @param TestObject $testObject
215+
* @param string $skipReason
210216
* @return TestObject
211217
*/
212-
public function skipTest($testObject)
218+
public function skipTest($testObject, $skipReason = null)
213219
{
214220
$annotations = $testObject->getAnnotations();
221+
$skipReason = $skipReason ?? 'ParentTestIsSkipped';
215222

216223
// Add skip to the group array if it doesn't already exist
217224
if (array_key_exists('skip', $annotations)) {
218225
return $testObject;
219226
} elseif (!array_key_exists('skip', $annotations)) {
220-
$annotations['skip'] = ['issueId' => "ParentTestDoesNotExist"];
227+
$annotations['skip'] = ['issueId' => $skipReason];
221228
}
222229

223230
$skippedTest = new TestObject(
@@ -229,6 +236,12 @@ public function skipTest($testObject)
229236
$testObject->getParentName()
230237
);
231238

239+
if (MftfApplicationConfig::getConfig()->verboseEnabled()) {
240+
LoggingUtil::getInstance()->getLogger(ObjectExtensionUtil::class)->debug(
241+
"{$testObject->getName()} is skipped due to {$skipReason}"
242+
);
243+
}
244+
232245
return $skippedTest;
233246
}
234247
}

0 commit comments

Comments
 (0)