concept expect in category flutter

This is an excerpt from Manning's book Flutter in Action.
Dart unit tests rely on three main functions from the test lib: test, expect, and group. The easiest way to explain how to write tests is to show some examples. This isn’t the full example, but an example of a single test—the most basic test possible. If you’ve written tests in any other modern language, this will be pretty easy to read.
The expect function (figure 11.3) works by taking in an actual as the first argument, which is what you’re testing, and a matcher, which is the expected outcome for the actual. If the two are the same, then the test will pass. Otherwise, expect will throw an error and fail the test.
Tests can be as complicated as you’d like, though. You can have multiple expect function calls in a single test. Consider this example where we’re testing that the counter can do multiple actions and stay in sync.
Listing 11.4. Multiple expect calls in a test
// backend/test/dart_test.dart test("counter increases and decreases", () { final counter = CompletedTodoCounter(); counter.increaseCounter(); expect(counter.completed, 1); #1 counter.increaseCounter(); // +1 counter.decreaseCounter(); // -1 counter.increaseCounter(); // +1 counter.increaseCounter(); // +1 counter.decreaseCounter(); // -1 expect(counter.completed, 2); #2 });
Widget tests use Matcher and Finder objects to compare what you expect to happen and what actually happened.