Testing Guide
Konsolidat's dbt project has 144 singular tests (.sql files under dbt_project/tests/: 139 at the top level and 5 under tests/staging/) and 129 schema tests (not_null, unique, accepted_values, relationships) declared in the model YAML files. Counted on 2026-11-08 (konsolidat f728d59); prd/checks/prd-01.sh recomputes both numbers from the repo.
Test Philosophy
Each singular test is a SQL query that returns the rows that violate an assertion. Zero rows = pass. Tests are named assert_<what> (or test_<what> for the staging contract tests).
Two severities:
error(the default): fails the build.dbt buildthen skips every model downstream of the test's parents.warn: logs, does not fail. 29 tests arewarntoday; they name data-quality problems that have known exceptions or that konsol validates on entry.
{{ config(severity='warn') }}
Several tests are red-first by design: a decision brief (repo/docs/developer-guide/decisions/) names the option, the test is written to fail, then the model is changed until it passes (for example assert_all_layers_present, konsolidat#238 option #238-4; assert_staging_not_stale, konsolidat#246 option #246-1).
Test Catalog
Severity is error unless marked (warn).
Trial balance, GL and the upload
assert_trial_balance_balances (warn), assert_period_net_equals_debit_minus_credit, assert_silver_gl_debit_credit_balance, assert_d365_gl_vouchers_balance, assert_is_credit_retired, assert_undeclared_accounts_in_trial_balance (warn), assert_fiscal_calendar_is_loaded, assert_partner_grain_not_fanned_out, assert_cast_to_decimal128_is_exact.
Upload (bronze_trial_balance_submissions, silver_tb_movements): assert_tb_submission_batches_balance, assert_tb_submission_has_basis, assert_tb_submission_rows_complete, assert_tb_submission_single_batch_per_period, assert_tb_submission_period_start_not_epoch, assert_entity_has_one_amount_basis, assert_tb_movements_balance, assert_tb_movements_cumulate_to_source, assert_tb_movements_difference_within_dimension, assert_year_end_close_declared, assert_year_end_close_invents_no_movement, assert_year_end_close_carried (warn).
Statements
assert_pnl_only_pnl_accounts, assert_bs_only_bs_accounts, assert_every_account_is_pnl_or_balance_sheet (warn), assert_is_equity_is_account_type_equity, assert_ytd_trial_balance_grain, assert_ytd_at_last_regular_period_equals_annual (warn), assert_prior_year_comparison_grain.
Cash flow: assert_cf_categories_equal_net_change, assert_consolidated_cf_reconciles, assert_cf_net_income_equals_group_pnl, assert_scoped_cash_flow_ytd_confined, assert_incremental_slice_preserved.
Governed reference data
assert_staging_not_stale (EMPTIED, LAGGING, NO_RECONCILE_RUN on the sync watermark), assert_governed_chart_declarations_usable (warn), assert_governed_chart_grain_unique (warn), assert_consolidation_group_root_unique, assert_scenario_rows_declared, assert_exchange_rate_positive, assert_exchange_rate_currencies_are_iso, assert_exchange_rate_sane_magnitude (warn), assert_conversion_factor_known, assert_governed_rate_grain_unique (warn), assert_governed_rate_sane (warn), assert_every_translated_currency_has_a_governed_rate (warn), assert_fx_magnitude_cases, assert_every_tb_entity_has_a_currency, assert_entity_less_gl_bounded (warn).
Translation and CTA
assert_translated_amount_formula, assert_group_amount_formula, assert_nci_plus_group_equals_translated, assert_nci_zero_for_full_ownership, assert_translation_follows_fx_method (warn), assert_translation_rate_resolved, assert_bs_translated_at_closing_rate (konsolidat#257), assert_equity_never_revalued (konsolidat#257), assert_equity_uses_historical_rate, assert_equity_historical_rate_is_asof, assert_equity_rate_coverage (warn), assert_declared_historical_has_a_rate (warn), assert_historical_is_equity_only, assert_cta_not_zero_when_rates_differ, assert_cta_zero_for_same_currency, assert_year_end_close_carries_no_cta (warn, konsolidat#259), assert_draft_excluded_from_consolidated.
Ownership and group structure
assert_ownership_chain_complete, assert_effective_ownership_is_path_sum (konsol#117; replaces the chain-product test), assert_effective_ownership_in_range, assert_ownership_uses_effective_date, assert_entity_in_one_consolidation_node, assert_ownership_paths_acyclic, assert_method_declared_for_multi_path, assert_tree_node_reached_by_links, assert_scope_resolves_to_entities, assert_nci_movement_reconciles, assert_equity_income_formula, assert_equity_method_single_line, assert_equity_method_no_ic_elim, assert_equity_method_journal_balances, assert_equity_associate_has_average_rate.
Intercompany
assert_ic_reconciliation_matched, assert_ic_pair_basis, assert_ic_pair_left_is_reversed, assert_ic_difference_cause, assert_ic_difference_not_from_ownership, assert_ic_match_status_cases, assert_ic_account_in_one_pair, assert_ic_difference_account_in_chart (warn), assert_ic_elimination_nets_zero, assert_ic_elimination_within_balance, assert_ic_full_view_nets_zero, assert_ic_nci_line_nets_zero, assert_ic_nci_leg_entity, assert_ic_nci_account_declared (warn), assert_unrealized_profit_elimination.
Topside journals and the consolidated TB
assert_topside_journal_balanced, assert_adjustment_type_populated, assert_auto_reversal_generated, assert_auto_reversal_negates_original, assert_auto_reversal_period_declared, assert_reversal_nets_to_zero, assert_fctb_entity_layer_ties, assert_all_layers_present, assert_end_to_end_bs_balances, assert_journal_grain_unique, assert_consolidation_journal_names_every_journal, assert_waterfall_reconciles.
Acquisitions, goodwill and disposals
assert_acquisition_journal_balances, assert_acquisition_accounts_declared, assert_acquired_balances_complete (warn), assert_acquisition_measured_in_period (warn), assert_deal_goodwill_matches_header, assert_deal_rate_resolved, assert_goodwill_calculated, assert_bargain_purchase_refused, assert_proration_pre_acquisition_excluded, assert_post_disposal_excluded, assert_goodwill_amortisation_journal_balances, assert_disposal_journal_balances, assert_disposal_accounts_declared, assert_disposal_has_balances (warn), assert_disposal_gain_loss_exists, assert_cta_recycled_on_disposal.
Budget, scenarios and variance
assert_spread_sums_to_annual, assert_spread_has_12_periods, assert_budget_fact_grain_unique, assert_variance_abs_formula, assert_favorable_revenue, assert_favorable_expense, assert_variance_covers_budget_scenarios, assert_variance_budget_matches_year, assert_variance_node_single_budget.
Reporting hierarchies
assert_hierarchy_closure_windows, assert_hierarchy_no_circular_ref, assert_hierarchy_all_entities_resolved, assert_hierarchy_rollup_ties, assert_hierarchy_node_as_of, assert_hierarchy_node_columns, assert_unassigned_as_of.
Staging contract (tests/staging/)
test_canonical_gl_entries_schema, test_canonical_gl_entries_not_null, test_canonical_gl_journals_balance, test_erp_source_valid, test_dimension_mappings_unique.
Running Tests
dbt test # everything
dbt test --select gold_trial_balance # tests on one model
dbt test --select assert_spread_sums_to_annual
dbt test --select tag:gold
dbt test --select "config.severity:warn"
The container's dbt is 1.11; profiles live in the project directory (--project-dir /home/frappe/dbt_project --profiles-dir /home/frappe/dbt_project). konsol's Assertion Run doctype (the period close) runs the close-assertion subset for a fiscal period and records each result.
Writing a New Test
1. Create the Test File
Create dbt_project/tests/assert_your_condition.sql:
{# What this test checks, and which decision or issue it holds (konsolidat#NNN). #}
select
key_column_1,
key_column_2,
computed_value,
expected_value,
abs(computed_value - expected_value) as gap
from {{ ref('gold_your_model') }}
where abs(computed_value - expected_value) > {{ materiality_floor() }}
2. Guidelines
- Red first. Write the test so it fails on the current model, then change the model. A test that cannot fail proves nothing (konsolidat#238/#249: a
LEFT JOIN ... is nullon aStringnever matched because ClickHouse fills a miss with'', not NULL; useNOT IN). - Return failing rows with enough context to diagnose them (entity, year, period, the values compared).
- Tolerance: use
{{ materiality_floor() }}(0.005), never a literal;tests/test_materiality_literal.pyfails on a stray literal. - Null handling: a singular test carries no
join_use_nullssetting, so a ClickHouse LEFT JOIN miss is the column default ('',0,1970-01-01), not NULL. - Dimensions: use the macros (
dim_select(),dim_partition_by(leading=true)), never a literaldim_*name; a site may declare none. - Severity:
{{ config(severity='warn') }}for a check that names a setup gap rather than a wrong number. - Cite the issue and, where there was one, the decision brief.
3. Test Patterns
Balance check (debits = credits):
select data_area_id, fiscal_year, fiscal_period,
abs(sum(period_debit) - sum(period_credit)) as imbalance
from {{ ref('gold_trial_balance') }}
group by data_area_id, fiscal_year, fiscal_period
having abs(sum(period_debit) - sum(period_credit)) > {{ materiality_floor() }}
Formula validation:
select *,
abs(translated_amount - (local_amount * translation_rate + retranslation_amount)) as gap
from {{ ref('gold_consolidated_trial_balance') }}
where abs(translated_amount - (local_amount * translation_rate + retranslation_amount)) > {{ materiality_floor() }}
Membership (a row has no parent): use NOT IN, not a LEFT JOIN null test.
select distinct main_account
from {{ ref('gold_trial_balance') }}
where main_account not in (select main_account_id from {{ ref('silver_main_accounts') }})
Count validation:
select scenario_id, data_area_id, fiscal_year, main_account,
count(distinct fiscal_period) as period_count
from {{ ref('gold_spread_budget') }}
group by scenario_id, data_area_id, fiscal_year, main_account
having count(distinct fiscal_period) != 12
4. Dimension Macros in Tests
select
data_area_id, fiscal_year, main_account,
{{ dim_select(trailing=true) }}
ytd_net_amount,
annual_total
from (
select *, sum(period_net_amount) over (
partition by data_area_id, fiscal_year, main_account{{ dim_partition_by(leading=true) }}
) as annual_total
from {{ ref('gold_ytd_trial_balance') }}
)
where abs(ytd_net_amount - annual_total) > {{ materiality_floor() }}
YAML Schema Tests
Column-level tests are declared in the _*__models.yml and _*__sources.yml files (data_tests: or tests:):
columns:
- name: data_area_id
data_tests:
- not_null
- name: main_account_id
data_tests:
- not_null
- unique
Available: not_null, unique, accepted_values, relationships.