Skip to content

Commit f1d9f9e

Browse files
authored
Merge pull request magento#605 from magento/MQE-2008
MQE-2008: Filter test generation and execution by severity
2 parents 3426237 + c215ab0 commit f1d9f9e

24 files changed

+388
-50
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
Magento Functional Testing Framework Changelog
22
================================================
3+
2.6.3
4+
-----
5+
6+
### New Feature
7+
* `--filter` option was added to `bin/mftf generate:tests` command. For more details please go to https://devdocs.magento.com/mftf/docs/commands/mftf.html#generatetests
38

49
2.6.2
510
-----

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "magento/magento2-functional-testing-framework",
33
"description": "Magento2 Functional Testing Framework",
44
"type": "library",
5-
"version": "2.6.2",
5+
"version": "2.6.3",
66
"license": "AGPL-3.0",
77
"keywords": ["magento", "automation", "functional", "testing"],
88
"config": {

composer.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev/tests/functional/tests/MFTF/DevDocs/Test/DeprecatedDevDocsTest.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<stories value="[Deprecated] MFTF DevDocs available"/>
1616
<title value="[Deprecated] Magento Functional Testing Framework Documentation is available."/>
1717
<description value="[Deprecated] Magento Functional Testing Framework Documentation is available."/>
18-
<severity value="CRITICAL"/>
18+
<severity value="MINOR"/>
1919
<group value="mftf"/>
2020
</annotations>
2121

dev/tests/unit/Magento/FunctionalTestFramework/Suite/Handlers/SuiteObjectHandlerTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function testGetSuiteObject()
6565
->withTestActions()
6666
->build();
6767

68-
$mockTestData = ['tests' => array_merge($mockSimpleTest, $mockGroup1Test1, $mockGroup1Test2, $mockGroup2Test1)];
68+
$mockTestData = array_merge($mockSimpleTest, $mockGroup1Test1, $mockGroup1Test2, $mockGroup2Test1);
6969
$this->setMockTestAndSuiteParserOutput($mockTestData, $mockData);
7070

7171
// parse and retrieve suite object with mocked data

dev/tests/unit/Magento/FunctionalTestFramework/Suite/SuiteGeneratorTest.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function testGenerateSuite()
6969
->withTestActions()
7070
->build();
7171

72-
$mockTestData = ['tests' => array_merge($mockSimpleTest)];
72+
$mockTestData = array_merge($mockSimpleTest);
7373
$this->setMockTestAndSuiteParserOutput($mockTestData, $mockData);
7474

7575
// parse and generate suite object with mocked data
@@ -105,7 +105,7 @@ public function testGenerateAllSuites()
105105
->withTestActions()
106106
->build();
107107

108-
$mockTestData = ['tests' => array_merge($mockSimpleTest)];
108+
$mockTestData = array_merge($mockSimpleTest);
109109
$this->setMockTestAndSuiteParserOutput($mockTestData, $mockData);
110110

111111
// parse and retrieve suite object with mocked data
@@ -172,7 +172,7 @@ public function testInvalidSuiteTestPair()
172172
->withAnnotations(['group' => [['value' => 'group2']]])
173173
->withTestActions()
174174
->build();
175-
$mockTestData = ['tests' => array_merge($mockSimpleTest, $mockSimpleTest2)];
175+
$mockTestData = array_merge($mockSimpleTest, $mockSimpleTest2);
176176
$this->setMockTestAndSuiteParserOutput($mockTestData, $mockSuiteData);
177177

178178
// Make invalid manifest
@@ -196,7 +196,7 @@ public function testNonExistentSuiteTestPair()
196196
->withAnnotations(['group' => [['value' => 'group1']]])
197197
->withTestActions()
198198
->build();
199-
$mockTestData = ['tests' => array_merge($mockSimpleTest)];
199+
$mockTestData = array_merge($mockSimpleTest);
200200
$this->setMockTestAndSuiteParserOutput($mockTestData, []);
201201

202202
// Make invalid manifest

dev/tests/unit/Magento/FunctionalTestFramework/Test/Handlers/TestObjectHandlerTest.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function testGetTestObject()
4141

4242
$resolverMock = new MockModuleResolverBuilder();
4343
$resolverMock->setup();
44-
$this->setMockParserOutput(['tests' => $mockData]);
44+
$this->setMockParserOutput($mockData);
4545

4646
// run object handler method
4747
$toh = TestObjectHandler::getInstance();
@@ -135,7 +135,7 @@ public function testGetTestsByGroup()
135135

136136
$resolverMock = new MockModuleResolverBuilder();
137137
$resolverMock->setup();
138-
$this->setMockParserOutput(['tests' => array_merge($includeTest, $excludeTest)]);
138+
$this->setMockParserOutput(array_merge($includeTest, $excludeTest));
139139

140140
// execute test method
141141
$toh = TestObjectHandler::getInstance();
@@ -184,7 +184,7 @@ public function testGetTestWithModuleName()
184184
$resolverMock = new MockModuleResolverBuilder();
185185
$resolverMock->setup(['Vendor_' . $moduleExpected => $filepath]);
186186

187-
$this->setMockParserOutput(['tests' => $mockData]);
187+
$this->setMockParserOutput($mockData);
188188
// Execute Test Method
189189
$toh = TestObjectHandler::getInstance();
190190
$actualTestObject = $toh->getObject($testDataArrayBuilder->testName);
@@ -212,7 +212,7 @@ public function testGetTestObjectWithInvalidExtends()
212212
->build();
213213
$resolverMock = new MockModuleResolverBuilder();
214214
$resolverMock->setup();
215-
$this->setMockParserOutput(['tests' => $testOne]);
215+
$this->setMockParserOutput($testOne);
216216

217217
$toh = TestObjectHandler::getInstance();
218218

@@ -250,7 +250,7 @@ public function testGetAllTestObjectsWithInvalidExtends()
250250

251251
$resolverMock = new MockModuleResolverBuilder();
252252
$resolverMock->setup();
253-
$this->setMockParserOutput(['tests' => array_merge($testOne, $testTwo)]);
253+
$this->setMockParserOutput(array_merge($testOne, $testTwo));
254254

255255
$toh = TestObjectHandler::getInstance();
256256

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function testGenerateExtendedTest()
6767
->withTestReference("simpleTest")
6868
->build();
6969

70-
$mockTestData = ['tests' => array_merge($mockSimpleTest, $mockExtendedTest)];
70+
$mockTestData = array_merge($mockSimpleTest, $mockExtendedTest);
7171
$this->setMockTestOutput($mockTestData);
7272

7373
// parse and generate test object with mocked data
@@ -112,7 +112,7 @@ public function testGenerateExtendedWithHooks()
112112
->withTestReference("simpleTest")
113113
->build();
114114

115-
$mockTestData = ['tests' => array_merge($mockSimpleTest, $mockExtendedTest)];
115+
$mockTestData = array_merge($mockSimpleTest, $mockExtendedTest);
116116
$this->setMockTestOutput($mockTestData);
117117

118118
// parse and generate test object with mocked data
@@ -143,7 +143,7 @@ public function testExtendedTestNoParent()
143143
->withTestReference("simpleTest")
144144
->build();
145145

146-
$mockTestData = ['tests' => array_merge($mockExtendedTest)];
146+
$mockTestData = array_merge($mockExtendedTest);
147147
$this->setMockTestOutput($mockTestData);
148148

149149
// parse and generate test object with mocked data
@@ -182,7 +182,7 @@ public function testExtendingExtendedTest()
182182
->withTestReference("simpleTest")
183183
->build();
184184

185-
$mockTestData = ['tests' => array_merge($mockParentTest, $mockSimpleTest, $mockExtendedTest)];
185+
$mockTestData = array_merge($mockParentTest, $mockSimpleTest, $mockExtendedTest);
186186
$this->setMockTestOutput($mockTestData);
187187

188188
$this->expectExceptionMessage("Cannot extend a test that already extends another test. Test: simpleTest");

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

+61
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,54 @@ 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(
123+
MftfApplicationConfig::class,
124+
['getFilterList' => new FilterList(['severity' => ["CRITICAL"]])]
125+
);
126+
127+
$actionInput = 'fakeInput';
128+
$actionObject = new ActionObject('fakeAction', 'comment', [
129+
'userInput' => $actionInput
130+
]);
131+
132+
$annotation1 = ['severity' => ['CRITICAL']];
133+
$annotation2 = ['severity' => ['MINOR']];
134+
$test1 = new TestObject(
135+
"test1",
136+
["fakeAction" => $actionObject],
137+
$annotation1,
138+
[],
139+
"filename"
140+
);
141+
$test2 = new TestObject(
142+
"test2",
143+
["fakeAction" => $actionObject],
144+
$annotation2,
145+
[],
146+
"filename"
147+
);
148+
AspectMock::double(TestGenerator::class, ['loadAllTestObjects' => ["sampleTest" => $test1, "test2" => $test2]]);
149+
150+
// Mock createCestFile to return name of tests that testGenerator tried to create
151+
$generatedTests = [];
152+
AspectMock::double(TestGenerator::class, ['createCestFile' => function ($arg1, $arg2) use (&$generatedTests) {
153+
$generatedTests[$arg2] = true;
154+
}]);
155+
156+
$testGeneratorObject = TestGenerator::getInstance("", ["sampleTest" => $test1, "test2" => $test2]);
157+
$testGeneratorObject->createAllTestFiles(null, []);
158+
159+
// Ensure Test1 was Generated but not Test 2
160+
$this->assertArrayHasKey('test1Cest', $generatedTests);
161+
$this->assertArrayNotHasKey('test2Cest', $generatedTests);
162+
}
102163
}

docs/commands/mftf.md

+1
Original file line numberDiff line numberDiff line change
@@ -159,6 +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: '<filterName>:<filterValue>'.<br/>Existing filter types: severity.<br/>Existing severity values: BLOCKER, CRITICAL, MAJOR, AVERAGE, MINOR.<br/>Example: --filter=severity:CRITICAL|
162163
| `--force` | Forces test generation, regardless of the module merge order defined in the Magento instance. Example: `generate:tests --force`. |
163164
| `-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`|
164165
| `--tests` | Defines the test configuration as a JSON string.|

src/Magento/FunctionalTestingFramework/Config/MftfApplicationConfig.php

+33-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\FunctionalTestingFramework\Config;
77

88
use Magento\FunctionalTestingFramework\Exceptions\TestFrameworkException;
9+
use Magento\FunctionalTestingFramework\Filter\FilterList;
910

1011
class MftfApplicationConfig
1112
{
@@ -25,6 +26,13 @@ class MftfApplicationConfig
2526
const LEVEL_NONE = "none";
2627
const MFTF_DEBUG_LEVEL = [self::LEVEL_DEFAULT, self::LEVEL_DEVELOPER, self::LEVEL_NONE];
2728

29+
/**
30+
* Contains object with test filters.
31+
*
32+
* @var FilterList
33+
*/
34+
private $filterList;
35+
2836
/**
2937
* Determines whether the user has specified a force option for generation
3038
*
@@ -74,14 +82,16 @@ class MftfApplicationConfig
7482
* @param boolean $verboseEnabled
7583
* @param string $debugLevel
7684
* @param boolean $allowSkipped
85+
* @param array $filters
7786
* @throws TestFrameworkException
7887
*/
7988
private function __construct(
8089
$forceGenerate = false,
8190
$phase = self::EXECUTION_PHASE,
8291
$verboseEnabled = null,
8392
$debugLevel = self::LEVEL_NONE,
84-
$allowSkipped = false
93+
$allowSkipped = false,
94+
$filters = []
8595
) {
8696
$this->forceGenerate = $forceGenerate;
8797

@@ -101,6 +111,7 @@ private function __construct(
101111
$this->debugLevel = self::LEVEL_DEVELOPER;
102112
}
103113
$this->allowSkipped = $allowSkipped;
114+
$this->filterList = new FilterList($filters);
104115
}
105116

106117
/**
@@ -112,6 +123,7 @@ private function __construct(
112123
* @param boolean $verboseEnabled
113124
* @param string $debugLevel
114125
* @param boolean $allowSkipped
126+
* @param array $filters
115127
* @return void
116128
* @throws TestFrameworkException
117129
*/
@@ -120,11 +132,19 @@ public static function create(
120132
$phase = self::EXECUTION_PHASE,
121133
$verboseEnabled = null,
122134
$debugLevel = self::LEVEL_NONE,
123-
$allowSkipped = false
135+
$allowSkipped = false,
136+
$filters = []
124137
) {
125138
if (self::$MFTF_APPLICATION_CONTEXT == null) {
126139
self::$MFTF_APPLICATION_CONTEXT =
127-
new MftfApplicationConfig($forceGenerate, $phase, $verboseEnabled, $debugLevel, $allowSkipped);
140+
new MftfApplicationConfig(
141+
$forceGenerate,
142+
$phase,
143+
$verboseEnabled,
144+
$debugLevel,
145+
$allowSkipped,
146+
$filters
147+
);
128148
}
129149
}
130150

@@ -196,4 +216,14 @@ public function getPhase()
196216
{
197217
return $this->phase;
198218
}
219+
220+
/**
221+
* Returns a class with registered filter list.
222+
*
223+
* @return FilterList
224+
*/
225+
public function getFilterList()
226+
{
227+
return $this->filterList;
228+
}
199229
}

src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class BaseGenerateCommand extends Command
3535
*
3636
* @var SymfonyStyle
3737
*/
38-
private $ioStyle = null;
38+
protected $ioStyle = null;
3939

4040
/**
4141
* Configures the base command.

0 commit comments

Comments
 (0)