What is Code Coverage?

Test Coverage နဲ့ Code Coverage ကွာသေးလားတော့မသိဘူး ခု ဖတ်ကြည့်တဲ့
guru မှာဖတ်ပီးသိရတာတော့ coverage အဓိက major method က ဒါတေရှိတယ်

  • Statement Coverage
  • Decision Coverage
  • Branch Coverage
  • Toggle Coverage
  • FSM Coverage

Statement Coverage ကတော့ ဖတ်ပီးပီးဆိုတော့
သူက code 10 ကြောင်းရေးထားရင် ကိုယ် test တဲ့ Scenario  တွေအကုန်က 10 ကြောင်းလုံးကို သွားထိမှ 100% coverage ဖြစ်တယ်ခေါ်တယ် ဘယ်လိုတွက်မလည်းဆိုတော့
ရှိတဲ့ code အကြောင်းရေက ၁၀ ကြောင်း ကိုယ်စမ်းလို့ ထိတဲ့ အကြောင်းရေက ၇ ကြောင်းပဲရှိတယ်ဆို
7/10 x 100 = 70% ပဲ
ကျန်တဲ့ ၃ ကြောင်းကို သွားထိစေမယ့် Scenario  မစမ်းထားတဲ့တွက် production ရောက်ရင် အဲကောင်က ပြသာနာဖြစ်စေနိုင်မယ် မစမ်းထားတဲ့တွက်

ဥပမာ ကိုယ်ရေးထားတဲ့ code က အောက်က အတိုင်းပေါ့

Prints (int a, int b) {                       ------------  Printsum is a function 
    int result = a+ b; 
    If (result> 0)
    	Print ("Positive", result)
    Else
    	Print ("Negative", result)
    }                                        -----------   End of the source code 

ဟုတ်ပီ ဒီရေးထားတဲ့ code ကို စမ်းရပီဆို ဒါက a နဲ့ b ပေါင်းပီး
ရလဒ်က 0 ထက်ကြီးရင် positive ငယ်ရင် negative ဆိုပီး စာထုတ်ပြတာ
ဒါကို စမ်းမယ့် Scenario  က positive ထွက်အောင်လည်း စမ်းရမယ် negative ထွက်အောင်လည်းစမ်းရမယ်


Scenario  1: a = 3, b = 6


အဲဒါဆို a = 3, b = 6 နဲ့စမ်းရင် positive ထွက်မယ် အဲမယ် ဒီ code က run ရင် result က positive ထွက်တာမို့ if else condition မှာ positive နဲ့ထွက်မယ် သွားထိမယ့် code စာကြောင်းတွေက အဝါနဲ့ပြထားတဲ့နေရာတေ သွားထိမယ် အဲတော့ ပုံသေနည်းနဲ့တွက်ရင် ဒီ ဟာနဲ့စမ်းတာမှာ ၇ ကြောင်းရှိတာမှ ၅ ကြောင်းထိတယ်
5/7 * 100 = 71% ရှိတယ်

Scenario  2: a = -3, b = -9

ဒီမှာဆို a = -3, b = -9 ဆိုတော့ ပေါင်းရင် အနှုတ်ပဲထွက်မယ် အဲတော့ if else condition မှာ If ကို စစ်တယ် 0 မကြီးဘူး else ကိုသွားမယ် negative ထွက်ပြမယ် အဲတော့ Print (“Positive”, result) အကြောင်းကိုပဲ မထိခဲ့တော့ ၇ ကြောင်းမှာ ၆ ကြောင်းထိတဲ့
6/7 * 100 = 85% ရှိတယ်
မထိခဲ့တဲ့ အကြောင်းက 4

အဲတော့ နောက်ဆုံး ပြန်တွက်ကြည့်ရင် scenario ၂ မျိုးစမ်းတဲ့ချိန်မှာ code 7 ကြောင်းလုံးကိုသွားထိတဲ့တွက် Statement Coverage test scenario က 100% ဖြစ်တယ်ပြောလို့ရတယ်


ပြောချင်တာက စမ်းတဲ့ Scenario  တေမှာ တခုခုသာ ကျန်ခဲ့ရင် user လက်ထဲရောက်မှ အဲနေရာရောက်ရင် error တက်မလား success ဖြစ်မလား မသိနိုင်ဘူး။ ဒါကတော့ Statement Coverage အကြောင်း

Leave a Reply

Your email address will not be published. Required fields are marked *

Up Next:

Covid 19 Third wave or Seasonal flu visit to home?

Covid 19 Third wave or Seasonal flu visit to home?