--- title: Unit Testing for Rules sort_rank: 6 --- # Unit Testing for Rules You can use `promtool` to test your rules. ```shell # For a single test file. ./promtool test rules test.yml # If you have multiple test files, say test1.yml,test2.yml,test2.yml ./promtool test rules test1.yml test2.yml test3.yml ``` ## Test file format ```yaml # This is a list of rule files to consider for testing. Globs are supported. rule_files: [ - ] [ evaluation_interval: | default = 1m ] # The order in which group names are listed below will be the order of evaluation of # rule groups (at a given evaluation time). The order is guaranteed only for the groups mentioned below. # All the groups need not be mentioned below. group_eval_order: [ - ] # All the tests are listed here. tests: [ - ] ``` ### `` ``` yaml # Series data [ interval: | default = evaluation_interval ] input_series: [ - ] # Name of the test group [ name: ] # Unit tests for the above data. # Unit tests for alerting rules. We consider the alerting rules from the input file. alert_rule_test: [ - ] # Unit tests for PromQL expressions. promql_expr_test: [ - ] # External labels accessible to the alert template. external_labels: [ : ... ] # External URL accessible to the alert template. # Usually set using --web.external-url. [ external_url: ] ``` ### `` ```yaml # This follows the usual series notation '{