Example module for integrations tests
Preferences
This example uses https://gitlab.met.tdintern.de/met/test-executor library to run the tests. This library needs to be installed as a global composer requirement inside your gitlab-runner. Inside our CI-Server (BDF) infrastructure there is a ready to use provisioning playbook for ansible. Please see https://gitlab.met.tdintern.de/met/ansible-ci/blob/master/playbooks/provision-worker-test-container-php72.yml
Execute tests
Every test run is split into three steps
- setup (before_script)
- tests (script)
- cleanup (after_script)
This is necessary since we do not destroy and recreate the testing containers after each run, the after_script ensures, that the environment will be cleaned finally.
Define your jobs inside your .gitlab-ci.yml
file as following to execute the tests:
job-name:
before_script:
- ~/.composer/vendor/met/test-executor/run.sh setup
script:
- ~/.composer/vendor/met/test-executor/run.sh tests
after_script:
- ~/.composer/vendor/met/test-executor/run.sh cleanup
Test configuration
While the test execution is the same for every kind of test and environment there are several variables, which allow you to specify your test requirements. The only required one ist EXECUTOR_SUITE
, which defines the scripts to be executed during the three steps of your test job.
Inside your .gitlab-ci.yml
this variable will be defined as follows:
job-name:
variables:
EXECUTOR_SUITE: module-integration
before_script:
- ~/.composer/vendor/met/test-executor/run.sh setup
script:
- ~/.composer/vendor/met/test-executor/run.sh tests
after_script:
- ~/.composer/vendor/met/test-executor/run.sh cleanup
Depending on the choosen EXECUTOR_SUITE, there is a bunch of additional variables, which could be set for your test job.
Executor Suites
module-integration
Purpose
This executor suite runs integration tests of a single module.
Most interesting variables
A list of all available variables will be displayed inside the job execution log.
Variable | Default Value | Description |
---|---|---|
MAGENTO_EDITION | community | Posible values: community, enterprise; This variable specifies the Magento edition, which will be installed to run the tests |
MAGENTO_VERSION | 2.3.* | This variable specifies the Magento version, which will be installed to run the tests; Every composer version spelling is possible. |
PHPUNIT_CONFIG_FILE | Test/Integration/phpunit.gitlab.xml | This variable specifies phpunit.xml file will be used for your integration tests. It is recommended to use the default settings. |
.gitlab-ci.yml
Example stages:
- test
integration-ce-22-php72:
stage: test
tags:
- php72
variables:
EXECUTOR_SUITE: module-integration
MAGENTO_EDITION: community
MAGENTO_VERSION: 2.2.*
COVERAGE_REPORT: html
before_script:
- ~/.composer/vendor/met/test-executor/run.sh setup
script:
- ~/.composer/vendor/met/test-executor/run.sh tests
after_script:
- ~/.composer/vendor/met/test-executor/run.sh cleanup
artifacts:
paths:
- ./report
expire_in: 1 week
integration-ce-23-php73:
stage: test
tags:
- php73
variables:
EXECUTOR_SUITE: module-integration
MAGENTO_EDITION: community
MAGENTO_VERSION: 2.3.*
before_script:
- ~/.composer/vendor/met/test-executor/run.sh setup
script:
- ~/.composer/vendor/met/test-executor/run.sh tests
after_script:
- ~/.composer/vendor/met/test-executor/run.sh cleanup