Thuta Learning
Flutter
AdvancedMobile Developmentအခြေခံ

Unit, Widget & Integration Testing

Flutterသင်ခန်းစာ 2725 မိနစ်

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

  • Unit, Widget & Integration Testing ရဲ့ widget, state နဲ့ lifecycle behavior ကိုရှင်းပြနိုင်ရန်
  • Responsive, failure နဲ့ interaction cases စမ်းနိုင်ရန်
  • Accessible, testable, performant Flutter code ရေးနိုင်ရန်

ရိုးရိုးလေး ရှင်းပြမယ်

Unit, Widget & Integration Testing ကို ရိုးရိုးလေးနားလည်မယ်

Unit, Widget & Integration Testing ကို feature slices ဖြင့်တည်ဆောက်ပြီး unit, widget နဲ့ integration tests ခွဲစစ်ပါ။ Debug/profile/release modes, frame time, rebuild count, accessibility နဲ့ deployment configuration ကို measurable acceptance criteria ထားပါ။

Problem → Why → Solution

ပြဿနာ — ဘာကြောင့် ဒီ concept လိုတာလဲ

Screen တစ်မျိုးတွင် sample output မှန်ရုံဖြင့် rebuild, overflow, accessibility, async နဲ့ lifecycle paths အားလုံးမှန်ပြီဟုယူဆခြင်း။

ဖြစ်လေ့ရှိတဲ့အမှား

build() ထဲ expensive work လုပ်ခြင်း၊ controller/subscription မပိတ်ခြင်း သို့ setState ကိုကျယ်သော subtree ပေါ်ခေါ်ခြင်း။

Core Concept — အလုပ်လုပ်ပုံကိုနားလည်မယ်

Unit, Widget & Integration Testing ကို feature slices ဖြင့်တည်ဆောက်ပြီး unit, widget နဲ့ integration tests ခွဲစစ်ပါ။ Debug/profile/release modes, frame time, rebuild count, accessibility နဲ့ deployment configuration ကို measurable acceptance criteria ထားပါ။

Mental Model
  1. Widget behavior
  2. Measure + verify
  3. Smooth accessible app

Unit, Widget & Integration Testing ရဲ့ widget, state နဲ့ lifecycle behavior ကိုရှင်းပြနိုင်ရန်

အဓိက Syntax / Pattern

dart
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
  testWidgets('shows the title', (tester) async {
    await tester.pumpWidget(const MaterialApp(home: Text('Tasks')));
    expect(find.text('Tasks'), findsOneWidget);
  });
}

Unit, Widget & Integration Testing ကို feature slices ဖြင့်တည်ဆောက်ပြီး unit, widget နဲ့ integration tests ခွဲစစ်ပါ။ Debug/profile/release modes, frame time, rebuild count, accessibility နဲ့ deployment configuration ကို measurable acceptance criteria ထားပါ။

Code ကို အဆင့်လိုက်ဖတ်မယ်

  1. Widget behaviorimport 'package:flutter/material.dart';

    Unit, Widget & Integration Testing ကို feature slices ဖြင့်တည်ဆောက်ပြီး unit, widget နဲ့ integration tests ခွဲစစ်ပါ။ Debug/profile/release modes, frame time, rebuild count, accessibility နဲ့ deployment configuration ကို measurable acceptance criteria ထားပါ။

  2. Measure + verifyawait tester.pumpWidget(const MaterialApp(home: Text(...

    Unit, Widget & Integration Testing ကို feature slices ဖြင့်တည်ဆောက်ပြီး unit, widget နဲ့ integration tests ခွဲစစ်ပါ။ Debug/profile/release modes, frame time, rebuild count, accessibility နဲ့ deployment configuration ကို measurable acceptance criteria ထားပါ။

  3. Smooth accessible app}

    Unit, Widget & Integration Testing example ကို small/large screen, text scaling, empty/loading/error, rapid interaction, navigation restore နဲ့ disposal cases ဖြင့် run/test လုပ်ပါ။ flutter analyze, widget tests နဲ့ profile mode ကိုလိုအပ်သလိုသုံးပါ။

Execution Flow
  1. Widget behavior
  2. Measure + verify
  3. Smooth accessible app

Success

Unit, Widget & Integration Testing ရဲ့ widget, state နဲ့ lifecycle behavior ကိုရှင်းပြနိုင်ရန်

Failure

Screen တစ်မျိုးတွင် sample output မှန်ရုံဖြင့် rebuild, overflow, accessibility, async နဲ့ lifecycle paths အားလုံးမှန်ပြီဟုယူဆခြင်း။

Unit, Widget & Integration Testing ကို feature slices ဖြင့်တည်ဆောက်ပြီး unit, widget နဲ့ integration tests ခွဲစစ်ပါ။ Debug/profile/release modes, frame time, rebuild count, accessibility နဲ့ deployment configuration ကို measurable acceptance criteria ထားပါ။

dart
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
  testWidgets('shows the title', (tester) async {
    await tester.pumpWidget(const MaterialApp(home: Text('Tasks')));
    expect(find.text('Tasks'), findsOneWidget);
  });
}
You should see
All tests passed!

Real-world usage

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

Unit, Widget & Integration Testing example ကို small/large screen, text scaling, empty/loading/error, rapid interaction, navigation restore နဲ့ disposal cases ဖြင့် run/test လုပ်ပါ။ flutter analyze, widget tests နဲ့ profile mode ကိုလိုအပ်သလိုသုံးပါ။

Mini challenge

ကိုယ်တိုင်တည်ဆောက်ကြည့်ပါ

Unit, Widget & Integration Testing example ကို small/large screen, text scaling, empty/loading/error, rapid interaction, navigation restore နဲ့ disposal cases ဖြင့် run/test လုပ်ပါ။ flutter analyze, widget tests နဲ့ profile mode ကိုလိုအပ်သလိုသုံးပါ။

  • Example ကို copy မလုပ်ဘဲ ပြန်ရေးပါ
  • Normal input နဲ့ edge case စမ်းပါ
  • Run မလုပ်မီ compiler/output result ကိုခန့်မှန်းပါ
dart
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
  testWidgets('shows the title', (tester) async {
    await tester.pumpWidget(const MaterialApp(home: Text('Tasks')));
    expect(find.text('Tasks'), findsOneWidget);
  });
}

ရလဒ်: Unit, Widget & Integration Testing ရဲ့ widget, state နဲ့ lifecycle behavior ကိုရှင်းပြနိုင်ရန်

အရိပ်အမြွက် ကြည့်ရန်

Unit, Widget & Integration Testing example ကို small/large screen, text scaling, empty/loading/error, rapid interaction, navigation restore နဲ့ disposal cases ဖြင့် run/test လုပ်ပါ။ flutter analyze, widget tests နဲ့ profile mode ကိုလိုအပ်သလိုသုံးပါ။

Quick Quiz 1 / 3

Unit, Widget & Integration Testing ရဲ့ အဓိကသဘောတရားက ဘာလဲ။

Quick Quiz 2 / 3

ဘယ်အမှားကို အရင်ဆုံးရှောင်သင့်လဲ။

Quick Quiz 3 / 3

Real project မှာ ဘယ်လိုအသုံးချသင့်လဲ။

ဒီသင်ခန်းစာမှာ မှတ်ထားရမယ့်အချက်များ

  • Widget behavior → Measure + verify → Smooth accessible app
  • Unit, Widget & Integration Testing ကို feature slices ဖြင့်တည်ဆောက်ပြီး unit, widget နဲ့ integration tests ခွဲစစ်ပါ။ Debug/profile/release modes, frame time, rebuild count, accessibility နဲ့ deployment configuration ကို measurable acceptance criteria ထားပါ။
  • Screen တစ်မျိုးတွင် sample output မှန်ရုံဖြင့် rebuild, overflow, accessibility, async နဲ့ lifecycle paths အားလုံးမှန်ပြီဟုယူဆခြင်း။
  • Unit, Widget & Integration Testing example ကို small/large screen, text scaling, empty/loading/error, rapid interaction, navigation restore နဲ့ disposal cases ဖြင့် run/test လုပ်ပါ။ flutter analyze, widget tests နဲ့ profile mode ကိုလိုအပ်သလိုသုံးပါ။

Introduction to widget testing — Flutter

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

  • Screen တစ်မျိုးတွင် sample output မှန်ရုံဖြင့် rebuild, overflow, accessibility, async နဲ့ lifecycle paths အားလုံးမှန်ပြီဟုယူဆခြင်း။
  • build() ထဲ expensive work လုပ်ခြင်း၊ controller/subscription မပိတ်ခြင်း သို့ setState ကိုကျယ်သော subtree ပေါ်ခေါ်ခြင်း။

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

Unit, Widget & Integration Testing example ကို small/large screen, text scaling, empty/loading/error, rapid interaction, navigation restore နဲ့ disposal cases ဖြင့် run/test လုပ်ပါ။ flutter analyze, widget tests နဲ့ profile mode ကိုလိုအပ်သလိုသုံးပါ။

အလုပ်ဖြစ်ကြောင်း ဒီလိုသိမယ်: All tests passed!

နောက်ဆုံးပြင်ဆင်ရက်

Progress ကို ဤ browser (ဤစက်) တွင်သာ သိမ်းထားပါသည်။ အခြားစက်များနှင့် sync မလုပ်ပါ။

ဤသင်ခန်းစာတွင် အမှားတွေ့ပါက အကြောင်းကြားရန်သင့် email app ကို ဤသင်ခန်းစာလိပ်စာ ဖြည့်ပြီးသားဖြင့် ဖွင့်ပေးပါမည် — သင်ကိုယ်တိုင် ပို့မှသာ ပို့မည်ဖြစ်သည်။

Unit, Widget & Integration Testing | Thuta Learning