x-pack/solutions/observability/plugins/apm/dev_docs/testing.md
We've got three ways of testing our code:
API tests are usually preferred. They're stable and reasonably quick, and give a good approximation of real-world usage. E2E testing is suitable for common and vital user journeys. They are however less stable than API tests. Unit testing is a good approach if you have a very specific piece of code with lots of possibilities that you want to test.
node x-pack/solutions/observability/plugins/apm/scripts/test/jest [--watch] [--updateSnapshot]
HTML coverage report can be found in target/coverage/jest after tests have run.
open target/coverage/jest/index.html
| Option | Description |
|---|---|
| --basic | Run tests with basic license |
| --trial | Run tests with trial license |
| --server | Only start ES and Kibana |
| --runner | Only run tests |
| --grep | Specify the specs to run |
| --grep-files | Specify the files to run |
| --inspect | Add --inspect-brk flag to the ftr for debugging |
| --times | Repeat the test n number of times |
The API tests are located in x-pack/solutions/observability/test/apm_api_integration/.
node x-pack/solutions/observability/plugins/apm/scripts/test/api [--trial/--basic] [--help]
The above command will start an ES instance on http://localhost:9220, a Kibana instance on http://localhost:5620 and run the api tests. Once the tests finish, the instances will be terminated.
# start server
node x-pack/solutions/observability/plugins/apm/scripts/test/api --server --basic
# run tests
node x-pack/solutions/observability/plugins/apm/scripts/test/api --runner --basic --grep-files=error_group_list
To update snapshots append --updateSnapshots to the --runner command:
node x-pack/solutions/observability/plugins/apm/scripts/test/api --runner --basic --updateSnapshots
(The test server needs to be running)
elastic / changeme)| Option | Description |
|---|---|
| --serverless | Loads serverless configuration |
| --stateful | Loads stateful configuration |
| --server | Only start ES and Kibana |
| --runner | Only run tests |
| --grep | Specify the specs to run |
| --grep-files | Specify the files to run |
| --inspect | Add --inspect-brk flag to the ftr for debugging |
| --times | Repeat the test n number of times |
Deployment-agnostic tests are located in x-pack/solutions/observability/test/api_integration_deployment_agnostic/apis/apm/index.ts.
node x-pack/solutions/observability/plugins/apm/scripts/test/dat [--serverless/--stateful] [--help]
The above command will start an ES instance on http://localhost:9220, a Kibana instance on http://localhost:5620 and run the api tests. Once the tests finish, the instances will be terminated.
# start server
node x-pack/solutions/observability/plugins/apm/scripts/test/dat --server --stateful
# run tests
node x-pack/solutions/observability/plugins/apm/scripts/test/dat --runner --stateful --grep-files=error_group_list
To update snapshots append --updateSnapshots to the --runner command:
node x-pack/solutions/observability/plugins/apm/scripts/test/dat --runner --stateful --updateSnapshots
(The test server needs to be running)
elastic / changeme)The E2E tests are located in x-pack/solutions/observability/plugins/apm/ftr_e2e.
Tests run on buildkite PR pipeline are parallelized (8 parallel jobs) and are orchestrated by the Cypress dashboard service. It can be configured in .buildkite/pipelines/pull_request/apm_cypress.yml with the property parallelism.
...
depends_on: build
parallelism: 3
...
node x-pack/solutions/observability/plugins/apm/scripts/test/e2e --open
node x-pack/solutions/observability/plugins/apm/scripts/test/e2e
node x-pack/solutions/observability/plugins/apm/scripts/test/e2e --headed
Accessibility tests are added on the e2e with checkA11y(), they will run together with cypress.
# Start server
node scripts/functional_tests_server --config x-pack/solutions/observability/test/functional/apps/apm/config.ts
# Run tests
node scripts/functional_test_runner --config x-pack/solutions/observability/test/functional/apps/apm/config.ts --grep='APM specs'
APM tests are located in x-pack/solutions/observability/test/functional/apps/apm.
For debugging access Elasticsearch on http://localhost:9220` (elastic/changeme)
diff --git a/x-pack/solutions/observability/plugins/apm/scripts/test/README.md b/x-pack/solutions/observability/plugins/apm/scripts/test/README.md
node scripts/functional_tests.js --config x-pack/solutions/observability/test/serverless/api_integration/configs/config.ts
# Start server
node scripts/functional_tests_server.js --config x-pack/solutions/observability/test/serverless/api_integration/configs/config.ts
# Run tests
node scripts/functional_test_runner --config=x-pack/solutions/observability/test/serverless/api_integration/configs/config.ts
yarn storybook apm
All files with a .stories.tsx extension will be loaded. You can access the development environment at http://localhost:9001.
For end-to-end (e.g. agent -> apm server -> elasticsearch <- kibana) development and testing of Elastic APM please check the the APM Integration Testing repository.
Data can also be generated using the kbn-synthtrace CLI.
*.spec.ts file. This makes it easy to find tests, and works well with our general approach of having single-purpose API endpoints.*.spec.ts files related to that particular feature.createAndRunApmMlJob helper function. This starts an ML job and returns only when it has completed, including any anomalies that are generated.createApmRule and waitForRuleStatus helpers. createApmRule sets some defaults when creating a rule, and waitForRuleStatus only return when a certain status is matching your expectations. This allows you to e.g. wait until an alert fires or recovers after exceeding a thresholdapm.readUser whenever possible. If the endpoint requires write privileges, use apm.writeUser or any of the other predefined roles, whichever apply. Don't use roles with higher access levels unless required.