Add a hooks_testing library (#1952)

Previous test for methods like `expect`, `expectLater`, and
`expectAsync` used internal details of the test runner like `LiveTest`
to check behaviors such as holding the test open and specific failure
behavior.

Add an abstraction `TestCaseMonitor` to hide the implementation details
of creating and running a `LocalTest`. Expose only the parts of
`LiveTest` which are used by current tests - the state and errors.
The new class is defined in a new library `hooks_testing` since it is
intended primarily for writing tests for code that uses the `hooks`
library.
Add a new `State` enum to hide some details of `LiveTest`.
There is already a class named `State` that holds the `Status` and
`Result` for a `LiveTest`. This `State` attempts to encode the useful
parts of the status and result into a single enum. We don't get much use
out of the separate status and result. The `Result` is always `passed`
when the `Status` is anything other than `complete` (it shouldn't be
read), and changing the `Result` to anything else is _always_
accompanied by setting the `status` to `complete`. The new enum also
lets us hide the `failure` and `error` distinction instead of adding new
dependencies to it.
This works towards #1465

Migrate tests under `test_api/test/frontend` for the tests which will be
migrating to `package:matcher` to use the new APIs. Move to a
`utils_new.dart` file which will be moved along with these tests, and
the old `utils.dart` file will remain for testing the scaffolding APIs.
Do not replace the `expectTestsBlock` utility, the usage of this utility
is not any more clear or readable than spelling out the full behavior in
the test.

Add tests in `checks` for the behavior of holding the test for pending
work, and for unawaited failures.
Add utilities for testing against a `TestMonitor` locally within the
test.
16 files changed
tree: 181c2269582b1e36a2e9ec7b10966e3941ce44aa
  1. .github/
  2. integration_tests/
  3. legacy_tests/
  4. pkgs/
  5. tool/
  6. .gitattributes
  7. .gitignore
  8. analysis_options.yaml
  9. CONTRIBUTING.md
  10. mono_repo.yaml
  11. README.md
README.md

Dart CI OpenSSF Scorecard

What's here?

Welcome! package:test is the standard testing library for Dart and Flutter. If you have questions about Dart testing, please see the docs for package:test. package:test_api and package:test_core are implementation details and generally not user-facing.

package:checks is a relatively new library for expressing test expectations. It's a more modern version of package:matcher and features a literate API.

Packages

PackageDescriptionVersion
checksA framework for checking values against expectations and building custom expectations.pub package
testA full featured library for writing and running Dart tests across platforms.pub package
test_apipub package
test_corepub package