# Quality gates ## Configuration You can use quality gates to enforce certain quality standards on your test results. To enable quality gates, you need to configure them in the Allure configuration file (e.g., `allurerc.js`): ```js import { defineConfig } from "allure"; export default defineConfig({ qualityGate: { rules: [ // first ruleset allows to have up to 10 failed tests in total, it won't fail in runtime and will report validation result in the end { maxFailures: 10, }, // second ruleset fails immediately if there is at least one critical test failure { // use id field to make ruleset's rules easier to identify id: "another-set", maxFailures: 0, fastFail: true, // validate only test results with critical severity label filter: (tr) => tr.labels.some((label) => label.name === "severity" && label.value === "critical"), }, ], }, }); ``` ## Command scope and dumps Commands that load test results evaluate the complete dataset handled by that invocation when `qualityGate` is present in their resolved configuration. This applies to both `allure run` and `allure generate`. The output format does not change the validation policy: quality gates are still evaluated when either command writes a dump. Allure finishes writing the report or dump before returning exit code `1` for a failed quality gate. Passed and failed rule results are stored in the artifact, while the terminal prints only failures. The `dump` configuration field and the `allure generate --dump` option serve opposite sides of the workflow: - `dump` in the configuration writes the invocation's state to a new archive. - `allure generate --dump ` restores an existing archive as input. This enables per-environment validation followed by report assembly. Each environment can use a configuration containing `environment`, `dump`, and `qualityGate`: ```js import { defineConfig } from "allure"; export default defineConfig({ environment: process.env.TEST_ENVIRONMENT, dump: `allure-results-${process.env.TEST_ENVIRONMENT}`, qualityGate: { rules: [{ maxFailures: 0 }], }, }); ``` The final job can then restore all environment dumps using a configuration without `qualityGate`: ```sh allure generate \ --dump allure-results-linux.zip \ --dump allure-results-windows.zip \ --output allure-report ``` In this form, final generation preserves and renders the quality-gate results stored by each environment without running an additional aggregate validation. Adding `qualityGate` to the final generation configuration intentionally evaluates the combined dataset and appends that invocation's validation results. ## Compatibility with rerun Quality gate validation works with `allure run --rerun`. The rerun count is a shared restart budget: every failed-test rerun, focused Quality Gate rerun, or full Quality Gate rerun consumes one slot. When a Quality Gate fast-fails, Allure stops the current test process and restarts the full test command. The interrupted result set is incomplete, so related tests alone aren't sufficient to build the next execution scope. When the test process completes, Allure creates a temporary test plan containing the current blocking failed and broken tests together with tests related to failed Quality Gate rules. The process restarts with `ALLURE_TESTPLAN_PATH` pointing to that plan. Rules without related tests don't trigger a focused rerun unless blocking failures are present. Use `--rerun=0` or omit `--rerun` to keep immediate fast-fail behavior without restarting the test process. ## Generated artifacts When quality gates are enabled, Allure writes `quality-gate.json` to the generated report root. The file contains a flat list of rule results and keeps related tests as report-scoped IDs in `testResults`. ```json [ { "success": false, "expected": 0, "actual": 1, "rule": "maxFailures", "message": "The number of failed tests 1 exceeds the allowed threshold value 0", "environment": "chrome", "testResults": ["4f1c2d"] } ] ``` Use the generated report root `test-results.json` to resolve these IDs. The registry contains compact test details that are enough to list and link related tests. ```json { "byId": { "4f1c2d": { "id": "4f1c2d", "name": "checkout rejects expired card", "status": "failed", "duration": 1234, "environment": "chrome" } } } ``` Together, these files allow CI integrations to show which rule failed and which tests are related to it without reading the full per-test result files. ## Using external rules You can use external quality gate rules implemented by the community – just provide them to the `use` field in the quality gate configuration: ```js import { defineConfig } from "allure"; import { rule1, rule2 } from "custom-rules-package"; export default defineConfig({ qualityGate: { rules: [ // define rulesets according the external rules signature ], use: [rule1, rule2], }, }); ``` > [!IMPORTANT] > When you want to use default and external rules together, don't forget to import default rules from the `allure/rules` package and include them in the `use` array: ```js import { defineConfig } from "allure"; // import default rules at once import { qualityGateDefaultRules } from "allure/rules"; // or import them separately import { maxFailuresRule, minTestsCountRule, successRateRule, maxDurationRule } from "allure/rules"; import { rule1, rule2 } from "custom-rules-package"; export default defineConfig({ qualityGate: { rules: [ // define rulesets according the external rules signature ], use: [...qualityGateDefaultRules, rule1, rule2], }, }); ``` If you don't re-assign `use` field, Allure will use only the default rules automatically without additional imports. ## Authoring custom rules You can create your own quality gate rules by implementing the `QualityGateRule` interface. Below is an example of a custom quality gate rule that checks if the number of test results matches an expected value: ```ts import type { QualityGateRule } from "allure/rules"; export const myRule: QualityGateRule = { rule: "myRule", message: ({ expected, actual }) => `The custom rule has failed. Expected: ${expected} doesn't equal to ${actual}`, validate: async ({ trs, expected }) => { const actual = trs.length; const passed = actual === expected; return { success: actual === expected, actual, }; }, }; ``` You can also aggregate validation data in runtime to make more complex rules. The rule below accumulates the number of test results across multiple invocations and checks if the total matches the expected value: ```ts import type { QualityGateRule } from "allure/rules"; export const myRule: QualityGateRule = { rule: "myRule", message: ({ expected, actual }) => `The custom rule has failed. Expected: ${expected} doesn't equal to ${actual}`, validate: async ({ trs, expected, state }) => { // there is no initial value in the state, so we use 0 as a fallback const previous = state.getResult() ?? 0; const actual = previous + trs.length; const passed = actual === expected; state.setResult(actual); return { success: actual === expected, actual, }; }, }; ``` Then, you can register your custom rule in the Allure configuration file: ```js import { defineConfig } from "allure"; import { myRule } from "./myRule"; export default defineConfig({ name: "Allure Report 3", qualityGate: { rules: [ { myRule: 100, }, ], use: [myRule], }, }); ``` > [!IMPORTANT] > If you're using TypeScript, ensure that you compiled your custom rule file before use! Allure doesn't support on-the-fly TypeScript compilation. ## Rules custom messages You can customize any rule message. To do this, provide a new `message` function to the specific rule in `use` array: ```js import { defineConfig } from "allure"; import { myRule } from "./myRule"; export default defineConfig({ name: "Allure Report 3", qualityGate: { rules: [ { myRule: 100, }, ], use: [ { // don't forget to use rest spread operator to keep rest rule's fields intact ...myRule, message: ({ expected, actual }) => `Custom message: expected ${expected}, got ${actual}`, }, ], }, }); ``` ## Using env variables in rules configuration Allure Runtime configuration file is a plain JavaScript so you can use environment variables to configure quality gate rules dynamically: ```js import { defineConfig } from "allure"; import { myRule } from "./myRule"; const { MY_RULE_VALUE } = process.env; export default defineConfig({ name: "Allure Report 3", qualityGate: { rules: [ { // use 100 as a fallback value when env variable is not set myRule: Number(MY_RULE_VALUE) || 100, }, ], use: [myRule], }, }); ``` ## Success rate The `successRate` rule compares an unrounded ratio from 0 to 1 against the configured minimum. For example, `successRate: 0.9` requires at least 90%. The ratio is `passed / (passed + failed + broken)`. Skipped and unknown results are excluded from this metric, but remain in report totals and status distributions. A run with no eligible results has a numeric success rate of zero and fails any positive success-rate threshold. Existing retry and resolution exclusions still apply before quality gate evaluation. Report success-rate charts use the same denominator. Displayed percentages are truncated to at most two decimal places. Pie slices and test-count proportions use all five statuses, so the passed slice percentage can differ from the success-rate caption. Empty pies display `???`; nonempty pies with no passed results display `0%`, with an explanation when no eligible results exist.