Skip to content

Commit d773983

Browse files
committed
MQE-2677: Add filter for groups
1 parent 5049d75 commit d773983

File tree

2 files changed

+102
-2
lines changed

2 files changed

+102
-2
lines changed

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

Lines changed: 101 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public function testAllowSkipped()
116116
*
117117
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException
118118
*/
119-
public function testFilter()
119+
public function testSeverityFilter()
120120
{
121121
// Mock filters for TestGenerator
122122
AspectMock::double(
@@ -160,4 +160,104 @@ public function testFilter()
160160
$this->assertArrayHasKey('test1Cest', $generatedTests);
161161
$this->assertArrayNotHasKey('test2Cest', $generatedTests);
162162
}
163+
164+
/**
165+
* Tests that TestGenerator createAllTestFiles correctly filters based on group included.
166+
*
167+
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException
168+
*/
169+
public function testIncludeGroupFilter()
170+
{
171+
// Mock filters for TestGenerator
172+
AspectMock::double(
173+
MftfApplicationConfig::class,
174+
['getFilterList' => new FilterList(['includeGroup' => ["someGroupValue"]])]
175+
);
176+
177+
$actionInput = 'fakeInput';
178+
$actionObject = new ActionObject('fakeAction', 'comment', [
179+
'userInput' => $actionInput
180+
]);
181+
182+
$annotation1 = ['group' => ['someGroupValue']];
183+
$annotation2 = ['group' => ['someOtherGroupValue']];
184+
$test1 = new TestObject(
185+
"test1",
186+
["fakeAction" => $actionObject],
187+
$annotation1,
188+
[],
189+
"filename"
190+
);
191+
$test2 = new TestObject(
192+
"test2",
193+
["fakeAction" => $actionObject],
194+
$annotation2,
195+
[],
196+
"filename"
197+
);
198+
AspectMock::double(TestGenerator::class, ['loadAllTestObjects' => ["sampleTest" => $test1, "test2" => $test2]]);
199+
200+
// Mock createCestFile to return name of tests that testGenerator tried to create
201+
$generatedTests = [];
202+
AspectMock::double(TestGenerator::class, ['createCestFile' => function ($arg1, $arg2) use (&$generatedTests) {
203+
$generatedTests[$arg2] = true;
204+
}]);
205+
206+
$testGeneratorObject = TestGenerator::getInstance("", ["sampleTest" => $test1, "test2" => $test2]);
207+
$testGeneratorObject->createAllTestFiles(null, []);
208+
209+
// Ensure Test1 was Generated but not Test 2
210+
$this->assertArrayHasKey('test1Cest', $generatedTests);
211+
$this->assertArrayNotHasKey('test2Cest', $generatedTests);
212+
}
213+
214+
/**
215+
* Tests that TestGenerator createAllTestFiles correctly filters based on group not included.
216+
*
217+
* @throws \Magento\FunctionalTestingFramework\Exceptions\TestReferenceException
218+
*/
219+
public function testExcludeGroupFilter()
220+
{
221+
// Mock filters for TestGenerator
222+
AspectMock::double(
223+
MftfApplicationConfig::class,
224+
['getFilterList' => new FilterList(['excludeGroup' => ['someGroupValue']])]
225+
);
226+
227+
$actionInput = 'fakeInput';
228+
$actionObject = new ActionObject('fakeAction', 'comment', [
229+
'userInput' => $actionInput
230+
]);
231+
232+
$annotation1 = ['group' => ['someGroupValue']];
233+
$annotation2 = ['group' => ['someOtherGroupValue']];
234+
$test1 = new TestObject(
235+
"test1",
236+
["fakeAction" => $actionObject],
237+
$annotation1,
238+
[],
239+
"filename"
240+
);
241+
$test2 = new TestObject(
242+
"test2",
243+
["fakeAction" => $actionObject],
244+
$annotation2,
245+
[],
246+
"filename"
247+
);
248+
AspectMock::double(TestGenerator::class, ['loadAllTestObjects' => ["sampleTest" => $test1, "test2" => $test2]]);
249+
250+
// Mock createCestFile to return name of tests that testGenerator tried to create
251+
$generatedTests = [];
252+
AspectMock::double(TestGenerator::class, ['createCestFile' => function ($arg1, $arg2) use (&$generatedTests) {
253+
$generatedTests[$arg2] = true;
254+
}]);
255+
256+
$testGeneratorObject = TestGenerator::getInstance("", ["sampleTest" => $test1, "test2" => $test2]);
257+
$testGeneratorObject->createAllTestFiles(null, []);
258+
259+
// Ensure Test2 was Generated but not Test 1
260+
$this->assertArrayNotHasKey('test1Cest', $generatedTests);
261+
$this->assertArrayHasKey('test2Cest', $generatedTests);
262+
}
163263
}

docs/commands/mftf.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ vendor/bin/mftf generate:tests [option] [<test name>] [<test name>] [--remove]
159159
| Option | Description|
160160
| ---| --- |
161161
| `--config=[<default> or <singleRun> or <parallel>]` | Creates a single manifest file with a list of all tests. The default location is `tests/functional/Magento/FunctionalTest/_generated/testManifest.txt`.<br/> You can split the list into multiple groups using `--config=parallel`; the groups will be generated in `_generated/groups/` like `_generated/groups/group1.txt, group2.txt, ...`.<br/> Available values: `default` (default), `singleRun`(same as `default`), and `parallel`.<br/> Example: `generate:tests --config=parallel`. |
162-
| `--filter` | Option to filter tests to be generated.<br/>Template: '&lt;filterName&gt;:&lt;filterValue&gt;'.<br/>Existing filter types: severity.<br/>Existing severity values: BLOCKER, CRITICAL, MAJOR, AVERAGE, MINOR.<br/>Example: --filter=severity:CRITICAL|
162+
| `--filter` | Option to filter tests to be generated.<br/>Template: '&lt;filterName&gt;:&lt;filterValue&gt;'.<br/>Existing filter types: severity, includeGroup, excludeGroup.<br/>Existing severity values: BLOCKER, CRITICAL, MAJOR, AVERAGE, MINOR.<br/>Example: `--filter=severity:CRITICAL`, `--filter=includeGroup:customer`|
163163
| `--force` | Forces test generation, regardless of the module merge order defined in the Magento instance. Example: `generate:tests --force`. |
164164
| `-i,--time` | Set time in minutes to determine the group size when `--config=parallel` is used. The __default value__ is `10`. Example: `generate:tests --config=parallel --time=15`|
165165
| `--tests` | Defines the test configuration as a JSON string.|

0 commit comments

Comments
 (0)