|
| 1 | +# How to use MFTF in CICD |
| 2 | + |
| 3 | +To integrate MFTF tests into your CICD pipeline, it is best to start with the conceptual flow of the pipeline code. |
| 4 | + |
| 5 | +## Concept |
| 6 | + |
| 7 | +The overall workflow that tests should follow is: |
| 8 | + |
| 9 | +- Obtain a Magento instance + install pre-requisites. |
| 10 | +- Generate the tests. |
| 11 | + - Set options for single or parallel running. |
| 12 | +- Delegate and run tests and gather test-run artifacts. |
| 13 | + - Re-run options. |
| 14 | +- Generate the Allure reports from the results. |
| 15 | + |
| 16 | +## Obtain a Magento instance |
| 17 | + |
| 18 | +To start, we need a Magento instance to operate against for test generation and execution. |
| 19 | + |
| 20 | +```bash |
| 21 | +git clone https://github.com/magento/magento2 |
| 22 | +``` |
| 23 | + |
| 24 | +or |
| 25 | + |
| 26 | +```bash |
| 27 | +composer create-project --repository=https://repo.magento.com/ magento/project-community-edition magento2ce |
| 28 | +``` |
| 29 | + |
| 30 | +For more information on installing magento see [Install Magento using Composer][]. |
| 31 | + |
| 32 | +After installing the Magento instance, set a couple of configurations to the Magento instance: |
| 33 | + |
| 34 | +```bash |
| 35 | +bin/magento config:set general/locale/timezone America/Los_Angeles |
| 36 | +bin/magento config:set admin/security/admin_account_sharing 1 |
| 37 | +bin/magento config:set admin/security/use_form_key 0 |
| 38 | +bin/magento config:set cms/wysiwyg/enabled disabled |
| 39 | +``` |
| 40 | + |
| 41 | +These set the default state of the Magento instance. If you wish to change the default state of the application (and have updated your tests sufficiently to account for it), this is the step to do it. |
| 42 | + |
| 43 | +If your magento instance has Two-Factor Authentication enabled, see [Configure 2FA][] to configure MFTF tests. |
| 44 | + |
| 45 | +## Install Allure |
| 46 | + |
| 47 | +This is required for generating the report after your test runs. See [Allure][] for details. |
| 48 | + |
| 49 | +## Generate tests |
| 50 | + |
| 51 | +### Single execution |
| 52 | + |
| 53 | +Generate tests based on what you want to run: |
| 54 | + |
| 55 | +```bash |
| 56 | +vendor/bin/mftf generate:tests |
| 57 | +``` |
| 58 | + |
| 59 | +This will generate all tests and a single manifest file under `dev/tests/acceptance/tests/functional/Magento/_generated/testManifest.txt`. |
| 60 | + |
| 61 | +### Parallel execution |
| 62 | + |
| 63 | +To generate all tests for use in parallel nodes: |
| 64 | + |
| 65 | +```bash |
| 66 | +vendor/bin/mftf generate:tests --config parallel |
| 67 | +``` |
| 68 | + |
| 69 | +This generates a folder under `dev/tests/acceptance/tests/functional/Magento/_generated/groups`. This folder contains several `group#.txt` files that can be used later with the `mftf run:manifest` command. |
| 70 | + |
| 71 | +## Delegate and run tests |
| 72 | + |
| 73 | +### Single execution |
| 74 | + |
| 75 | +If you are running on a single node, call: |
| 76 | + |
| 77 | +```bash |
| 78 | +vendor/bin/mftf run:manifest dev/tests/acceptance/tests/functional/Magento/_generated/testManifest.txt |
| 79 | +``` |
| 80 | + |
| 81 | +### Parallel execution |
| 82 | + |
| 83 | +You can optimize your pipeline by running tests in parallel across multiple nodes. |
| 84 | + |
| 85 | +Tests can be split up into roughly equal running groups using `--config parallel`. |
| 86 | + |
| 87 | +You do not want to perform installations on each node again and build it. So, to save time, stash pre-made artifacts from earlier steps and un-stash on the nodes. |
| 88 | + |
| 89 | +The groups can be then distributed on each of the nodes and run separately in an isolated environment. |
| 90 | + |
| 91 | +- Stash artifacts from main node and un-stash on current node. |
| 92 | +- Run `vendor/bin/mftf run:manifest <current_group.txt>` on current node. |
| 93 | +- Gather artifacts from `dev/tests/acceptance/tests/_output` from current node to main node. |
| 94 | + |
| 95 | +### Rerun options |
| 96 | + |
| 97 | +In either single or parallel execution, to re-run failed tests, simply add the `run:failed` command after executing a manifest: |
| 98 | + |
| 99 | +```bash |
| 100 | +vendor/bin/mftf run:failed |
| 101 | +``` |
| 102 | + |
| 103 | +### Generate Allure report |
| 104 | + |
| 105 | +In the main node, generate reports using your `<path_to_results>` into a desired output path: |
| 106 | + |
| 107 | +```bash |
| 108 | +allure generate <path_to_results> -c -o <path_to_output> |
| 109 | +``` |
| 110 | + |
| 111 | +<!-- Link definitions --> |
| 112 | +[Install Magento using Composer]: https://devdocs.magento.com/guides/v2.4/install-gde/composer.html |
| 113 | +[Configure 2FA]: ../configure-2fa.md |
| 114 | +[Allure]: https://docs.qameta.io/allure/ |
0 commit comments