Skip to content

Commit bcf0d44

Browse files
manjusha729Manjusha.SKevinBKozan
authored
MQE-2233 : Support xUnit-compatible Output Format (#187)
* MQE-2233 : Support xUnit-compatible Output Format * MQE-2233 : Support xUnit-compatible Output Format * modified testname in doc * added not empty condition * added not empty condition * added doc for new option + Added the right description regarding where file is moved * added doc for new option + Added the right description regarding where file is moved Co-authored-by: Manjusha.S <manjusha.s@BLR1-LMC-N71373.local> Co-authored-by: Kevin Kozan <kkozan@adobe.com>
1 parent 7c45556 commit bcf0d44

File tree

4 files changed

+76
-16
lines changed

4 files changed

+76
-16
lines changed

docs/commands/mftf.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ Generates and executes the listed groups of tests using Codeception.
353353
#### Usage
354354

355355
```bash
356-
vendor/bin/mftf run:group [--skip-generate|--remove] [--] <group1> [<group2>]
356+
vendor/bin/mftf run:group [--skip-generate|--remove|--xml] [--] <group1> [<group2>]
357357
```
358358

359359
#### Options
@@ -363,6 +363,7 @@ vendor/bin/mftf run:group [--skip-generate|--remove] [--] <group1> [<group2>]
363363
| `-k, --skip-generate` | Skips generating from the source XML. Instead, the command executes previously-generated groups of tests. |
364364
| `-r, --remove` | Removes previously generated suites and tests before the actual generation and run. |
365365
| `--debug` | Performs schema validations on XML files. `run:group` implicitly performs schema validation on merged files. It does not indicate the file name where the error is encountered. `--debug` performs per-file validation and returns additional debug information (such as the filename where an error occurred).|
366+
| `--xml` | Generate JUnit XML Log (default: "report.xml") |
366367

367368
#### Examples
368369

@@ -385,7 +386,7 @@ Generates and executes tests by name using Codeception.
385386
#### Usage
386387

387388
```bash
388-
vendor/bin/mftf run:test [--skip-generate|--remove] [--] <name1> [<name2>]
389+
vendor/bin/mftf run:test [--skip-generate|--remove|--xml] [--] <name1> [<name2>]
389390
```
390391

391392
#### Options
@@ -395,6 +396,7 @@ vendor/bin/mftf run:test [--skip-generate|--remove] [--] <name1> [<name2>]
395396
| `-k, --skip-generate` | Skips generating from the source XML. Instead, the command executes previously-generated groups of tests. |
396397
| `-r, --remove` | Remove previously generated suites and tests. |
397398
| `--debug` | Performs schema validations on XML files. `run:test` implicitly performs schema validation on merged files. It does not indicate the file name where the error is encountered. `--debug` performs per-file validation and returns additional debug information (such as the filename where an error occurred).|
399+
| `--xml` | Generate JUnit XML Log (default: "report.xml") |
398400

399401
#### Examples
400402

src/Magento/FunctionalTestingFramework/Console/BaseGenerateCommand.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,4 +364,29 @@ protected function applyAllFailed()
364364
} catch (TestFrameworkException $e) {
365365
}
366366
}
367+
/**
368+
* Codeception creates default xml file with name report.xml .
369+
* This function renames default file name with name of the test.
370+
*
371+
* @param string $xml
372+
* @param string $fileName
373+
* @param OutputInterface $output
374+
* @return void
375+
* @throws \Exception
376+
*/
377+
public function movingXMLFileFromSourceToDestination($xml, $fileName, $output)
378+
{
379+
if(!empty($xml) && file_exists($this->getTestsOutputDir().'report.xml')) {
380+
if (!file_exists($this->getTestsOutputDir().'xml')) {
381+
mkdir($this->getTestsOutputDir().'xml' , 0777, true);
382+
}
383+
$fileName = str_replace("Cest.php", "",$fileName);
384+
$existingFileName = $this->getTestsOutputDir().'report.xml';
385+
$newFileName = $this->getTestsOutputDir().'xml/'.$fileName.'_report.xml';
386+
$output->writeln( "<info>".sprintf(" report.xml file is moved to ".
387+
$this->getTestsOutputDir().'xml/'. ' location with the new name '.$fileName.'_report.xml')."</info>") ;
388+
rename($existingFileName , $newFileName);
389+
}
390+
}
391+
367392
}

src/Magento/FunctionalTestingFramework/Console/RunTestCommand.php

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ protected function configure()
4141
{
4242
$this->setName("run:test")
4343
->setDescription("generation and execution of test(s) defined in xml")
44+
->addOption(
45+
'xml',
46+
'xml',
47+
InputOption::VALUE_NONE,
48+
"creates xml report for executed test"
49+
)
4450
->addArgument(
4551
'name',
4652
InputArgument::OPTIONAL | InputArgument::IS_ARRAY,
@@ -134,11 +140,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
134140
$testConfigArray = json_decode($testConfiguration, true);
135141

136142
if (isset($testConfigArray['tests'])) {
137-
$this->runTests($testConfigArray['tests'], $output);
143+
$this->runTests($testConfigArray['tests'], $output, $input);
138144
}
139145

140146
if (isset($testConfigArray['suites'])) {
141-
$this->runTestsInSuite($testConfigArray['suites'], $output);
147+
$this->runTestsInSuite($testConfigArray['suites'], $output, $input);
142148
}
143149

144150
// Add all failed tests in 'failed' file
@@ -152,12 +158,16 @@ protected function execute(InputInterface $input, OutputInterface $output): int
152158
*
153159
* @param array $tests
154160
* @param OutputInterface $output
161+
* @param InputInterface $input
155162
* @return void
156163
* @throws TestFrameworkException
157164
* @throws \Exception
158165
*/
159-
private function runTests(array $tests, OutputInterface $output)
166+
private function runTests(array $tests, OutputInterface $output, InputInterface $input)
160167
{
168+
$xml = ($input->getOption('xml'))
169+
? '--xml'
170+
: "";
161171
if ($this->pauseEnabled()) {
162172
$codeceptionCommand = self::CODECEPT_RUN_FUNCTIONAL;
163173
} else {
@@ -179,16 +189,18 @@ private function runTests(array $tests, OutputInterface $output)
179189
}
180190

181191
if ($this->pauseEnabled()) {
182-
$fullCommand = $codeceptionCommand . $testsDirectory . $testName . ' --verbose --steps --debug';
192+
$fullCommand = $codeceptionCommand . $testsDirectory . $testName . ' --verbose --steps --debug '.$xml;
183193
if ($i !== count($tests) - 1) {
184194
$fullCommand .= self::CODECEPT_RUN_OPTION_NO_EXIT;
185195
}
186196
$this->returnCode = max($this->returnCode, $this->codeceptRunTest($fullCommand, $output));
187197
} else {
188-
$fullCommand = $codeceptionCommand . $testsDirectory . $testName . ' --verbose --steps';
198+
$fullCommand = $codeceptionCommand . $testsDirectory . $testName . ' --verbose --steps '.$xml;
189199
$this->returnCode = max($this->returnCode, $this->executeTestCommand($fullCommand, $output));
190200
}
191-
201+
if (!empty($xml)) {
202+
$this->movingXMLFileFromSourceToDestination($xml, $testName, $output);
203+
}
192204
// Save failed tests
193205
$this->appendRunFailed();
194206
}
@@ -199,16 +211,20 @@ private function runTests(array $tests, OutputInterface $output)
199211
*
200212
* @param array $suitesConfig
201213
* @param OutputInterface $output
214+
* @param InputInterface $input
202215
* @return void
203216
* @throws \Exception
204217
*/
205-
private function runTestsInSuite(array $suitesConfig, OutputInterface $output)
218+
private function runTestsInSuite(array $suitesConfig, OutputInterface $output, InputInterface $input)
206219
{
220+
$xml = ($input->getOption('xml'))
221+
? '--xml'
222+
: "";
207223
if ($this->pauseEnabled()) {
208-
$codeceptionCommand = self::CODECEPT_RUN_FUNCTIONAL . '--verbose --steps --debug';
224+
$codeceptionCommand = self::CODECEPT_RUN_FUNCTIONAL . '--verbose --steps --debug '.$xml;
209225
} else {
210226
$codeceptionCommand = realpath(PROJECT_ROOT . '/vendor/bin/codecept')
211-
. ' run functional --verbose --steps ';
227+
. ' run functional --verbose --steps '.$xml;
212228
}
213229

214230
$count = count($suitesConfig);
@@ -226,7 +242,9 @@ private function runTestsInSuite(array $suitesConfig, OutputInterface $output)
226242
} else {
227243
$this->returnCode = max($this->returnCode, $this->executeTestCommand($fullCommand, $output));
228244
}
229-
245+
if (!empty($xml)) {
246+
$this->movingXMLFileFromSourceToDestination($xml, $suite, $output);
247+
}
230248
// Save failed tests
231249
$this->appendRunFailed();
232250
}

src/Magento/FunctionalTestingFramework/Console/RunTestGroupCommand.php

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,15 @@ class RunTestGroupCommand extends BaseGenerateCommand
2929
protected function configure()
3030
{
3131
$this->setName('run:group')
32-
->setDescription('Execute a set of tests referenced via group annotations')
32+
->setDescription(
33+
'Execute a set of tests referenced via group annotations'
34+
)
35+
->addOption(
36+
'xml',
37+
'xml',
38+
InputOption::VALUE_NONE,
39+
"creates xml report for executed group"
40+
)
3341
->addOption(
3442
'skip-generate',
3543
'k',
@@ -58,6 +66,9 @@ protected function configure()
5866
*/
5967
protected function execute(InputInterface $input, OutputInterface $output): int
6068
{
69+
$xml = ($input->getOption('xml'))
70+
? '--xml'
71+
: "";
6172
$skipGeneration = $input->getOption('skip-generate');
6273
$force = $input->getOption('force');
6374
$groups = $input->getArgument('groups');
@@ -104,9 +115,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
104115
}
105116

106117
if ($this->pauseEnabled()) {
107-
$commandString = self::CODECEPT_RUN_FUNCTIONAL . '--verbose --steps --debug';
118+
$commandString = self::CODECEPT_RUN_FUNCTIONAL . '--verbose --steps --debug '.$xml;
108119
} else {
109-
$commandString = realpath(PROJECT_ROOT . '/vendor/bin/codecept') . ' run functional --verbose --steps';
120+
$commandString = realpath(
121+
PROJECT_ROOT . '/vendor/bin/codecept'
122+
) . ' run functional --verbose --steps '.$xml;
110123
}
111124

112125
$exitCode = -1;
@@ -130,7 +143,9 @@ function ($type, $buffer) use ($output) {
130143
}
131144
);
132145
}
133-
146+
if (!empty($xml)) {
147+
$this->movingXMLFileFromSourceToDestination($xml, $groups[$i].'_'.'group', $output);
148+
}
134149
// Save failed tests
135150
$this->appendRunFailed();
136151
}

0 commit comments

Comments
 (0)