- dbt မှာ data testing နဲ့ unit testing ဆိုပြီး ၂ မျိုး ခွဲပြောတယ်။ ## Data Testing - Data Testing နဲ့ ပတ်သတ်ရင်လဲ Singular data test နဲ့ Generic data test ဆိုပြီး ၂ မျိုး ခွဲပြောတယ်။ #### Singular Test - Singular Data Test ကတော့ ကိုယ်ရေးချင်တဲ့ test ကို SQL နဲ့ ရေးပြီး `test-paths:["tests"]` မှာ ကြေညာထားတဲ့ tests folder အောက်မှာ `.sql` file အနေနဲ့ သွားသိမ်းရင် ရပီ။ သူက ကိုယ် test ချင်တဲ့ scope အပြင် ဘာမှ ထပ်ပြီးတော့ dynamically ထည့်လို့ မရဘူး။ - Singular Test examples - `tests/assert_total_payment_is_positive.sql` ```sql -- Refunds have a negative amount, so the total amount should always be >= 0. -- Therefore return records where total_amount < 0 to make the test fail. select order_id, sum(amount) as total_amount from {{ ref('fct_payments') }} group by 1 having total_amount < 0 ``` #### Generic Test - Generic data test ကကျတော့ ထပ်တလဲလဲ ကြိမ်ဖန်များစွာ ပြန်သုံးလို့ ရအောင် macro ပုံစံမျိုး ရေးထားတာ။ ဒါပေမယ့် macro နဲ့ မတူတာကျတော့ သူ့ကို `{% test ... %} ... {% endtest %}` ပုံစံမျိုး ရေးတယ်။ သူကကျ dynamic ဖြစ်ဖြစ် သုံးလို့ ရအောင် argument တွေ လက်ခံလို့ ရတယ်။ - ဥပမာ - ```sql {% test not_null(model, column_name) %} select * from {{ model }} where {{ column_name }} is null {% endtest %} ``` - dbt မှာ default ပါတဲ့ generic function တွေက `unique`, `not_null`, `accepted_values` , `relationships` ## Unit Test - Unit test ကိုတော့ dbt v1.8 နဲ့ အထက်မှာမှ စသုံးလို့ ရတယ်။