Flutter รองรับการทดสอบหลายประเภท — unit tests (ตรรกะ), widget tests (UI components) และ integration tests (กระแสการทำงานของแอปทั้งหมด) กลยุทธ์การทดสอบที่ดีช่วยเพิ่มความน่าเชื่อถือและความมั่นใจ และเครื่องมือทดสอบของ Flutter ทำให้สิ่งนี้เป็นไปได้ในทางปฏิบัติ
Unit tests — ทดสอบตรรกะ
// test pure logic (functions, classes, business logic) — fast, no UI
test('adds two numbers', () {
expect(add(2, 3), 5);
});
test('Cart calculates total', () {
final cart = Cart()..add(Item(price: 10));
expect(cart.total, 10);
});
