Skip to content

Commit 8c85258

Browse files
MQE-3121 MFTF config parallel to support input test names from a file (#167)
* MQE-3121 MFTF config parallel to support input test names from a file * fix static checks and ac. * updated doc * added example * Update mftf.md Co-authored-by: Kevin Kozan <[email protected]> Co-authored-by: Kevin Kozan <[email protected]>
1 parent 94c4397 commit 8c85258

File tree

2 files changed

+61
-11
lines changed

2 files changed

+61
-11
lines changed

docs/commands/mftf.md

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,23 @@ vendor/bin/mftf generate:tests
4242
vendor/bin/mftf generate:tests AdminLoginSuccessfulTest StorefrontPersistedCustomerLoginTest
4343
```
4444

45+
### Generate tests by testNames.txt file
46+
47+
```bash
48+
vendor/bin/mftf generate:tests -p path/to/your/testNames.txt
49+
```
50+
51+
This command generate all tests specified in a testNames.txt file.
52+
53+
#### Example
54+
55+
```bash
56+
testName1
57+
testName2
58+
testNameN
59+
suiteName:testInSuite
60+
```
61+
4562
### Generate test by test and suite name
4663

4764
```bash
@@ -183,7 +200,7 @@ vendor/bin/mftf generate:tests [option] [<test name>] [<test name>] [--remove]
183200
The configuration to generate a single test with no suites:
184201

185202
```json
186-
{
203+
{
187204
"tests":[
188205
"general_test1" //Generate the "general_test1" test.
189206
],
@@ -194,9 +211,9 @@ The configuration to generate a single test with no suites:
194211
The configuration to generate a single test in the suite:
195212

196213
```json
197-
{
214+
{
198215
"tests": null, // No tests outside the suite configuration will be generated.
199-
"suites":{
216+
"suites":{
200217
"sample":[ // The suite that contains the test.
201218
"suite_test1" // The test to be generated.
202219
]
@@ -207,8 +224,8 @@ The configuration to generate a single test in the suite:
207224
Complex configuration to generate a few non-suite tests, a single test in a suite, and an entire suite:
208225

209226
```json
210-
{
211-
"tests":[
227+
{
228+
"tests":[
212229
"general_test1",
213230
"general_test2",
214231
"general_test3"
@@ -368,7 +385,7 @@ vendor/bin/mftf run:test LoginCustomerTest StorefrontCreateCustomerTest
368385

369386
Runs a testManifest.txt file.
370387

371-
This command runs all tests specified in a testManifest.xml file. It does not generate tests for you. You must do that as first.
388+
This command runs all tests specified in a testManifest.xml file. It does not generate tests for you. You must do that as first.
372389

373390
#### Usage
374391

@@ -449,7 +466,7 @@ The example parameters are taken from the `etc/config/.env.example` file.
449466

450467
### `static-checks`
451468

452-
Runs all or specific MFTF static-checks on the test codebase that MFTF is currently attached to.
469+
Runs all or specific MFTF static-checks on the test codebase that MFTF is currently attached to.
453470
Behavior for determining what tests to run is as follows:
454471

455472
* If test names are specified, only those tests are run.
@@ -469,7 +486,7 @@ vendor/bin/mftf static-checks [<names>]...
469486
| Option | Description |
470487
|-----------------------|-----------------------------------------------------------------------------------------------------------|
471488
| `-p, --path` | Path to a MFTF test module to run "deprecatedEntityUsage" and "pauseActionUsage" static check scripts. Option is ignored by other static check scripts.
472-
489+
473490
#### Examples
474491

475492
To check what existing static check scripts are available
@@ -478,7 +495,7 @@ To check what existing static check scripts are available
478495
vendor/bin/mftf static-checks --help
479496
```
480497

481-
To run all existing static check scripts
498+
To run all existing static check scripts
482499

483500
```bash
484501
vendor/bin/mftf static-checks
@@ -527,7 +544,7 @@ vendor/bin/mftf static-checks testDependencies actionGroupArguments
527544
|`deprecatedEntityUsage`| Checks that deprecated test entities are not being referenced.|
528545
|`annotations`| Checks various details of test annotations, such as missing annotations or duplicate annotations.|
529546
|`pauseUsage`| Checks that pause action is not used in action groups, tests or suites.|
530-
547+
531548
#### Defining ruleset
532549

533550
The `static-checks` command will look for a `staticRuleset.json` file under either:
@@ -623,7 +640,7 @@ vendor/bin/mftf codecept:run functional --verbose --steps -g default
623640

624641
<div class="bs-callout-warning">
625642
<p>
626-
Note: You may want to limit the usage of this Codeception command with arguments and options for "acceptance" only, since it is what's supported by MFTF.
643+
Note: You may want to limit the usage of this Codeception command with arguments and options for "acceptance" only, since it is what's supported by MFTF.
627644
When using this command, you should change "acceptance" to "functional" when referring to Codeception documentation.
628645
</p>
629646
</div>

src/Magento/FunctionalTestingFramework/Console/GenerateTestsCommand.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ protected function configure()
8080
. '<info>Existing severity values:</info> BLOCKER, CRITICAL, MAJOR, AVERAGE, MINOR.' . PHP_EOL
8181
. '<info>Example:</info> --filter=severity:CRITICAL'
8282
. ' --filter=includeGroup:customer --filter=excludeGroup:customerAnalytics' . PHP_EOL
83+
)->addOption(
84+
'path',
85+
'p',
86+
InputOption::VALUE_REQUIRED,
87+
'path to a test names file.',
8388
);
8489

8590
parent::configure();
@@ -113,6 +118,11 @@ protected function execute(InputInterface $input, OutputInterface $output)
113118
list($filterType, $filterValue) = explode(':', $filter);
114119
$filterList[$filterType][] = $filterValue;
115120
}
121+
$path = $input->getOption('path');
122+
// check filepath is given for generate test file
123+
if (!empty($path)) {
124+
$tests = $this->generateTestFileFromPath($path);
125+
}
116126
// Set application configuration so we can references the user options in our framework
117127
try {
118128
MftfApplicationConfig::create(
@@ -311,4 +321,27 @@ private function parseConfigParallelOptions($time, $groups)
311321
throw new FastFailException("'groups' option must be an integer and greater than 0");
312322
}
313323
}
324+
325+
/**
326+
* @param string $path
327+
* @return array
328+
* @throws TestFrameworkException
329+
*/
330+
private function generateTestFileFromPath(string $path): array
331+
{
332+
if (!file_exists($path)) {
333+
throw new TestFrameworkException("Could not find file $path. Check the path and try again.");
334+
}
335+
336+
$test_names = file($path, FILE_IGNORE_NEW_LINES);
337+
$tests = [];
338+
foreach ($test_names as $test_name) {
339+
if (empty(trim($test_name))) {
340+
continue;
341+
}
342+
$test_name_array = explode(' ', trim($test_name));
343+
$tests = array_merge($tests, $test_name_array);
344+
}
345+
return $tests;
346+
}
314347
}

0 commit comments

Comments
 (0)