ရိုးရိုးလေး ရှင်းပြမယ်
Testing with Swift Testing ကို ရိုးရိုးလေးနားလည်မယ်
Testing with Swift Testing ကိုUI, domain state, persistence/service နဲ့tests ခွဲထားသောvertical slices ဖြင့်လုပ်ပါ။ Normal, boundary, nil, error, cancellation နဲ့concurrency paths ကိုrepeatable tests ဖြင့်စစ်ပြီးmain-actor work ကိုမပိတ်ပါနှင့်။
Problem → Why → Solution
ပြဿနာ — ဘာကြောင့် ဒီ concept လိုတာလဲ
Sample output တစ်ခုမှန်ရုံဖြင့်nil, ownership, actor isolation နဲ့error paths အားလုံးမှန်ပြီဟုယူဆခြင်း။
ဖြစ်လေ့ရှိတဲ့အမှား
Force unwrap သို့unchecked shared mutable state ဖြင့်compiler safety ကိုကျော်ခြင်း။
Core Concept — အလုပ်လုပ်ပုံကိုနားလည်မယ်
Testing with Swift Testing ကိုUI, domain state, persistence/service နဲ့tests ခွဲထားသောvertical slices ဖြင့်လုပ်ပါ။ Normal, boundary, nil, error, cancellation နဲ့concurrency paths ကိုrepeatable tests ဖြင့်စစ်ပြီးmain-actor work ကိုမပိတ်ပါနှင့်။
- Typed value
- Swift expression / function
- Safe result
Testing with Swift Testing ရဲ့type, ownership နဲ့runtime behavior ကိုရှင်းပြနိုင်ရန်
အဓိက Syntax / Pattern
import Testing
func total(_ values: [Int]) -> Int { values.reduce(0, +) }
@Test("Totals empty and populated collections")
func totals() {
#expect(total([]) == 0)
#expect(total([1, 2, 3]) == 6)
}Testing with Swift Testing ကိုUI, domain state, persistence/service နဲ့tests ခွဲထားသောvertical slices ဖြင့်လုပ်ပါ။ Normal, boundary, nil, error, cancellation နဲ့concurrency paths ကိုrepeatable tests ဖြင့်စစ်ပြီးmain-actor work ကိုမပိတ်ပါနှင့်။
Code ကို အဆင့်လိုက်ဖတ်မယ်
- Typed value
import TestingTesting with Swift Testing ကိုUI, domain state, persistence/service နဲ့tests ခွဲထားသောvertical slices ဖြင့်လုပ်ပါ။ Normal, boundary, nil, error, cancellation နဲ့concurrency paths ကိုrepeatable tests ဖြင့်စစ်ပြီးmain-actor work ကိုမပိတ်ပါနှင့်။
- Swift expression / function
func totals() {Testing with Swift Testing ကိုUI, domain state, persistence/service နဲ့tests ခွဲထားသောvertical slices ဖြင့်လုပ်ပါ။ Normal, boundary, nil, error, cancellation နဲ့concurrency paths ကိုrepeatable tests ဖြင့်စစ်ပြီးmain-actor work ကိုမပိတ်ပါနှင့်။
- Safe result
}Testing with Swift Testing example ကိုempty, nil, boundary, invalid, error နဲ့cancellation cases ဖြင့်run/test လုပ်ပါ။ Value copy, shared reference, actor isolation နဲ့main-actor effects ကိုလိုအပ်သလိုစစ်ပါ။
- Typed value
- Swift expression / function
- Safe result
Success
Testing with Swift Testing ရဲ့type, ownership နဲ့runtime behavior ကိုရှင်းပြနိုင်ရန်
Failure
Sample output တစ်ခုမှန်ရုံဖြင့်nil, ownership, actor isolation နဲ့error paths အားလုံးမှန်ပြီဟုယူဆခြင်း။
Testing with Swift Testing ကိုUI, domain state, persistence/service နဲ့tests ခွဲထားသောvertical slices ဖြင့်လုပ်ပါ။ Normal, boundary, nil, error, cancellation နဲ့concurrency paths ကိုrepeatable tests ဖြင့်စစ်ပြီးmain-actor work ကိုမပိတ်ပါနှင့်။
import Testing
func total(_ values: [Int]) -> Int { values.reduce(0, +) }
@Test("Totals empty and populated collections")
func totals() {
#expect(total([]) == 0)
#expect(total([1, 2, 3]) == 6)
}Expectations 2 ခုအောင်မည်Real-world usage
လက်တွေ့ Project မှာ ဘယ်လိုသုံးမလဲ
Testing with Swift Testing example ကိုempty, nil, boundary, invalid, error နဲ့cancellation cases ဖြင့်run/test လုပ်ပါ။ Value copy, shared reference, actor isolation နဲ့main-actor effects ကိုလိုအပ်သလိုစစ်ပါ။
Mini challenge
ကိုယ်တိုင်တည်ဆောက်ကြည့်ပါ
Testing with Swift Testing example ကိုempty, nil, boundary, invalid, error နဲ့cancellation cases ဖြင့်run/test လုပ်ပါ။ Value copy, shared reference, actor isolation နဲ့main-actor effects ကိုလိုအပ်သလိုစစ်ပါ။
- Example ကို copy မလုပ်ဘဲ ပြန်ရေးပါ
- Normal input နဲ့ edge case စမ်းပါ
- Run မလုပ်မီ compiler/output result ကိုခန့်မှန်းပါ
import Testing
func total(_ values: [Int]) -> Int { values.reduce(0, +) }
@Test("Totals empty and populated collections")
func totals() {
#expect(total([]) == 0)
#expect(total([1, 2, 3]) == 6)
}ရလဒ်: Testing with Swift Testing ရဲ့type, ownership နဲ့runtime behavior ကိုရှင်းပြနိုင်ရန်
အရိပ်အမြွက် ကြည့်ရန်
Testing with Swift Testing example ကိုempty, nil, boundary, invalid, error နဲ့cancellation cases ဖြင့်run/test လုပ်ပါ။ Value copy, shared reference, actor isolation နဲ့main-actor effects ကိုလိုအပ်သလိုစစ်ပါ။
Quick Quiz 1 / 3
Quick Quiz 2 / 3
Quick Quiz 3 / 3
ဒီသင်ခန်းစာမှာ မှတ်ထားရမယ့်အချက်များ
- Typed value → Swift expression / function → Safe result
- Testing with Swift Testing ကိုUI, domain state, persistence/service နဲ့tests ခွဲထားသောvertical slices ဖြင့်လုပ်ပါ။ Normal, boundary, nil, error, cancellation နဲ့concurrency paths ကိုrepeatable tests ဖြင့်စစ်ပြီးmain-actor work ကိုမပိတ်ပါနှင့်။
- Sample output တစ်ခုမှန်ရုံဖြင့်nil, ownership, actor isolation နဲ့error paths အားလုံးမှန်ပြီဟုယူဆခြင်း။
- Testing with Swift Testing example ကိုempty, nil, boundary, invalid, error နဲ့cancellation cases ဖြင့်run/test လုပ်ပါ။ Value copy, shared reference, actor isolation နဲ့main-actor effects ကိုလိုအပ်သလိုစစ်ပါ။
Swift Testing — Apple Developer