|
| 1 | +# How to use MFTF in CICD |
| 2 | + |
| 3 | +If you want to integrate MFTF tests into your CICD pipeline, then it's best to start with the conceptual flow of the pipeline code. |
| 4 | + |
| 5 | +## Concept |
| 6 | + |
| 7 | +The overall workflow that tests should follow is thus: |
| 8 | + |
| 9 | +* Obtain Magento instance + install pre-requisites |
| 10 | +* Generate tests for running |
| 11 | + * Options for single/parallel running |
| 12 | +* Delegate and run tests + gather test run artifacts |
| 13 | + * Re-run options |
| 14 | +* Generate Allure report from aggregate |
| 15 | + |
| 16 | +### Obtain Magento instance |
| 17 | + |
| 18 | +To start, we need a Magento instance to operate against for generation and execution. |
| 19 | + |
| 20 | +``` |
| 21 | +$ git clone https://github.com/magento/magento2 |
| 22 | +or |
| 23 | +$ composer create-project --repository=https://repo.magento.com/ magento/project-community-edition magento2ce |
| 24 | +``` |
| 25 | + |
| 26 | +For more information on installing magento see [Install Magento using Composer]. |
| 27 | + |
| 28 | +After installing the Magento instance, you need to set a couple of configurations to the magento instance: |
| 29 | + |
| 30 | +``` |
| 31 | +$ bin/magento config:set general/locale/timezone America/Los_Angeles |
| 32 | +$ bin/magento config:set admin/security/admin_account_sharing 1 |
| 33 | +$ bin/magento config:set admin/security/use_form_key 0 |
| 34 | +$ bin/magento config:set cms/wysiwyg/enabled disabled |
| 35 | +``` |
| 36 | + |
| 37 | +These help set the state for the `default` state of the Magento instance. If you are wanting to change the default state of the application (and have merged into the tests sufficiently to account for it), this is the step in which you would do it. |
| 38 | + |
| 39 | +#### Install allure |
| 40 | + |
| 41 | +This will be required to generate the report after your test runs. See [Allure] for details. |
| 42 | + |
| 43 | + |
| 44 | +### Generate tests |
| 45 | + |
| 46 | +#### Single execution |
| 47 | + |
| 48 | +Simply generate tests based on what you want to run: |
| 49 | + |
| 50 | +``` |
| 51 | +$ vendor/bin/mftf generate:tests |
| 52 | +``` |
| 53 | + |
| 54 | +This will generate all tests, and a single manifest file under `dev/tests/acceptance/tests/functional/Magento/FunctionalTest/_generated/testManifest.txt` |
| 55 | + |
| 56 | +#### Parallel execution |
| 57 | + |
| 58 | +To generate all tests for use in parallel nodes: |
| 59 | + |
| 60 | +``` |
| 61 | +$ vendor/bin/mftf generate:tests --config parallel |
| 62 | +``` |
| 63 | + |
| 64 | +This will generate a folder under `dev/tests/acceptance/tests/functional/Magento/FunctionalTest/_generated/groups`. This folder contains several `group#.txt` files that can be used later with the `mftf run:manifest` command. |
| 65 | + |
| 66 | +### Delegate and run tests |
| 67 | + |
| 68 | +#### Single execution |
| 69 | +If you are running on a single node, this step is simply to call: |
| 70 | + |
| 71 | +``` |
| 72 | +$ vendor/bin/mftf run:manifest dev/tests/acceptance/tests/functional/Magento/FunctionalTest/_generated/testManifest.txt |
| 73 | +``` |
| 74 | + |
| 75 | +#### Parallel execution |
| 76 | +To run MFTF tests in parallel, you will need to clone the contents of the current node and duplicate them depending on how many nodes you have available for use. |
| 77 | + |
| 78 | +* Clone contents of current node as a baseline |
| 79 | +* For each `groups/group#.txt` file: |
| 80 | + * Set a node's contents to the baseline |
| 81 | + * Run `vendor/bin/mftf run:manifest <current_group.txt>` |
| 82 | + * Gather artifacts from `dev/tests/acceptance/tests/_output` from current node to master |
| 83 | + |
| 84 | +#### Rerun options |
| 85 | +In either single or parallel execution, to re-run failed tests simply add a `run:failed` command after executing a manifest: |
| 86 | + |
| 87 | +``` |
| 88 | +$ vendor/bin/mftf run:failed |
| 89 | +``` |
| 90 | + |
| 91 | +### Generate Allure report |
| 92 | + |
| 93 | +In the master node, simply generate using your `<path_to_results>` into a desired output path |
| 94 | + |
| 95 | +``` |
| 96 | +$ allure generate <path_to_results> -c -o <path_to_output> |
| 97 | +``` |
| 98 | + |
| 99 | +<!-- Link definitions --> |
| 100 | +[Install Magento using Composer]: https://devdocs.magento.com/guides/v2.3/install-gde/composer.html |
| 101 | +[Allure]: https://docs.qameta.io/allure/ |
0 commit comments