fail, which throws a TestFailure, is understood and handled by the test framework.
For example, when using "run test" in VSCode, the test will run (successfully) and report a failure (successfully):
With throw StateError, an unhandled exception is triggered, and the test does not run, and instead you get a stack dump:
This is a minor but easy to fix QoL improvement when developing package:flutter_tools.