Skip to content

Commit 1c7b03b

Browse files
committed
MQE-2008: Filter test generation and execution by severity
- Unit test
1 parent a9f5bba commit 1c7b03b

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

dev/tests/unit/Magento/FunctionalTestFramework/Util/TestGeneratorTest.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
use AspectMock\Test as AspectMock;
1010

11+
use Magento\FunctionalTestingFramework\Filter\FilterList;
1112
use Magento\FunctionalTestingFramework\Test\Objects\ActionObject;
1213
use Magento\FunctionalTestingFramework\Test\Objects\TestHookObject;
1314
use Magento\FunctionalTestingFramework\Test\Objects\TestObject;
@@ -17,6 +18,16 @@
1718

1819
class TestGeneratorTest extends MagentoTestCase
1920
{
21+
/**
22+
* After method functionality
23+
*
24+
* @return void
25+
*/
26+
public function tearDown()
27+
{
28+
AspectMock::clean();
29+
}
30+
2031
/**
2132
* Basic test to check exceptions for incorrect entities.
2233
*
@@ -99,4 +110,53 @@ public function testAllowSkipped()
99110
$this->assertContains($actionInput, $output);
100111
$this->assertContains($beforeActionInput, $output);
101112
}
113+
114+
/**
115+
* Tests that TestGenerator createAllTestFiles correctly filters based on severity
116+
*
117+
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException
118+
*/
119+
public function testFilter()
120+
{
121+
// Mock filters for TestGenerator
122+
AspectMock::double(MftfApplicationConfig::class, ['getFilterList' => new FilterList(['severity' => ["CRITICAL"]])]);
123+
124+
$actionInput = 'fakeInput';
125+
$actionObject = new ActionObject('fakeAction', 'comment', [
126+
'userInput' => $actionInput
127+
]);
128+
129+
$annotation1 = ['severity' => ['CRITICAL']];
130+
$annotation2 = ['severity' => ['MINOR']];
131+
$test1 = new TestObject(
132+
"test1",
133+
["fakeAction" => $actionObject],
134+
$annotation1,
135+
[],
136+
"filename"
137+
);
138+
$test2 = new TestObject(
139+
"test2",
140+
["fakeAction" => $actionObject],
141+
$annotation2,
142+
[],
143+
"filename"
144+
);
145+
AspectMock::double(TestGenerator::class, ['loadAllTestObjects' => ["sampleTest" => $test1, "test2" => $test2]]);
146+
147+
// Mock createCestFile to return name of tests that testGenerator tried to create
148+
$generatedTests = [];
149+
AspectMock::double(TestGenerator::class, ['createCestFile' => function ($arg1, $arg2) use (&$generatedTests){
150+
$generatedTests[$arg2] = true;
151+
}]);
152+
153+
$testGeneratorObject = TestGenerator::getInstance("", ["sampleTest" => $test1, "test2" => $test2]);
154+
$testGeneratorObject->createAllTestFiles(null, []);
155+
156+
// Ensure Test1 was Generated but not Test 2
157+
$this->assertArrayHasKey('test1Cest', $generatedTests);
158+
$this->assertArrayNotHasKey('test2Cest', $generatedTests);
159+
160+
}
161+
102162
}

0 commit comments

Comments
 (0)