Thuta Learning
Dart
AdvancedProgrammingbeginner

Testing with package:test

Dartသင်ခန်းစာ 25

ဒီခန်းပြီးရင် ဘာတတ်သွားမလဲ

  • Testing with package:test ရဲ့ type နဲ့ runtime behavior ကိုရှင်းပြနိုင်ရန်
  • Null, failure, boundary နဲ့ async cases စမ်းနိုင်ရန်
  • Safe, idiomatic, testable Dart code ရေးနိုင်ရန်

Testing with package:test ကို library boundaries, domain logic, I/O နဲ့ tests ခွဲထားသော vertical slices ဖြင့်တည်ဆောက်ပါ။ Normal, null, empty, invalid, async-error နဲ့ cancellation cases ကို repeatable tests ဖြင့်စစ်ပါ။

ပိုပြီးနားလည်ထားရမယ့် အချက်

Testing with package:test ကို library boundaries, domain logic, I/O နဲ့ tests ခွဲထားသော vertical slices ဖြင့်တည်ဆောက်ပါ။ Normal, null, empty, invalid, async-error နဲ့ cancellation cases ကို repeatable tests ဖြင့်စစ်ပါ။

လက်တွေ့မှာ ဘယ်လိုအသုံးချမလဲ

Testing with package:test example ကို null, empty, boundary, invalid, async-error နဲ့ cancellation cases ဖြင့် run/test လုပ်ပါ။ dart format, dart analyze နဲ့ dart test ကိုသုံးပြီး Future/Stream subscription နဲ့ isolate boundary ကိုလိုအပ်သလိုစစ်ပါ။

ဒီသင်ခန်းစာပြီးရင်

dart
import 'package:test/test.dart';

int total(Iterable<int> values) => values.fold(0, (a, b) => a + b);

void main() {
  group('total', () {
    test('handles empty and populated values', () {
      expect(total([]), 0);
      expect(total([1, 2, 3]), 6);
    });
  });
}
You should see
All tests passed!

ကိုယ်တိုင်စမ်းကြည့်ရန်

Testing with package:test example ကို null, empty, boundary, invalid, async-error နဲ့ cancellation cases ဖြင့် run/test လုပ်ပါ။ dart format, dart analyze နဲ့ dart test ကိုသုံးပြီး Future/Stream subscription နဲ့ isolate boundary ကိုလိုအပ်သလိုစစ်ပါ။

Null/Async သတိပေးချက်

Sample output တစ်ခုမှန်ရုံဖြင့် null, promotion, Future, Stream နဲ့ isolate paths အားလုံးမှန်ပြီဟုယူဆခြင်း။

Dart testingDart

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • Sample output တစ်ခုမှန်ရုံဖြင့် null, promotion, Future, Stream နဲ့ isolate paths အားလုံးမှန်ပြီဟုယူဆခြင်း။
  • dynamic, ! သို့မပိတ်ထားသော Stream subscription ဖြင့် type safety နဲ့ resource lifecycle ကိုကျော်ခြင်း။

လက်တွေ့လေ့ကျင့်ခန်း

Testing with package:test example ကို null, empty, boundary, invalid, async-error နဲ့ cancellation cases ဖြင့် run/test လုပ်ပါ။ dart format, dart analyze နဲ့ dart test ကိုသုံးပြီး Future/Stream subscription နဲ့ isolate boundary ကိုလိုအပ်သလိုစစ်ပါ။

You'll know it worked when: All tests passed!