Chuyển đến nội dung chính

Bài đăng

Hiển thị các bài đăng có nhãn Golden Tests

Test Flutter đỏ vì đúng lý do: widget, golden và integration

Có hai loại test đỏ. Một loại báo cho bạn biết hành vi đã đổi. Loại kia báo rằng máy đang bận, hoặc CI runner dùng font khác, hoặc ai đó vừa thêm hiệu ứng shimmer ở màn hình cách đó ba tầng. Loại thứ hai còn tệ hơn không có test, vì một team đã quen bấm “re-run pipeline” cũng là một team đã quen phớt lờ pipeline. Flutter làm cho chuyện này dễ sai theo một kiểu rất riêng. flutter_test cho bạn một đồng hồ giả và một màn hình ảo — đó là món quà — nhưng API lại dâng sẵn pumpAndSettle() , và pumpAndSettle() là một vòng lặp pump frame cho đến khi không còn frame nào được lên lịch. Chĩa nó vào một progress indicator vô hạn thì nó sẽ pump suốt mười phút rồi ném lỗi. Golden test là cái bẫy còn lại: chúng thật sự là cách rẻ nhất để bắt regression về mặt hình ảnh, và cũng là thứ mà các team xóa đi sau tuần thứ ba của điệp khúc “máy tôi xanh, CI thì đỏ”. Bài này là kim tự tháp test áp vào Flutter, không kèm quảng cáo: mỗi lớp thật sự chứng minh được gì, một ví dụ chạy được cho từng lớp, rồi mộ...

Flutter tests that fail for a reason: widget, golden and integration

There are two kinds of red test. One tells you a behaviour changed. The other tells you the machine was busy, or the CI runner has a different font, or somebody added a shimmer effect three screens away. The second kind is worse than no test at all, because a team that has learned to re-run the pipeline has also learned to ignore the pipeline. Flutter makes this easy to get wrong in a specific way. flutter_test gives you a fake clock and a virtual screen, which is a gift — but the API surface hands you pumpAndSettle() on a plate, and pumpAndSettle() is a loop that pumps frames until nothing is scheduled. Point it at an indeterminate progress indicator and it will pump for ten minutes and then throw. Golden tests are the other trap: they are genuinely the cheapest way to catch visual regressions, and they are also the thing teams delete after the third week of “passes locally, fails on CI.” This is the pyramid applied to Flutter without the sales pitch: what each layer actually pro...