TestHarness<T extends ApplicationChannel> class Null safety

Manages application lifecycle for the purpose of testing the application.

You install a test harness at the beginning of a test's main function. Before test cases are run, the harness starts an instance of your application on the same isolate as the tests. After your tests complete, the harness stops the application from running.

You typically create a subclass of TestHarness that is used for all tests in an application. The subclass overrides callbacks beforeStart and afterStart to configure the application. This configuration might be adding an application's database schema to a test database, or to create OAuth2 client identifiers for use during test. See also TestHarnessORMMixin and TestHarnessAuthMixin for adding common behaviors like these to your harness.


    class Harness extends ApplicationHarness<MyChannel> {
      Future afterStart() async {
        channel.service.uri = Uri.parse("http://localhost:4040");

    void main() {
      final harness = Harness()..install();

      test("GET /example returns 200", () async {
        final response = await harness.agent.get("/example");
        expectResponse(response, 200);




agent Agent?
The default Agent that makes requests to the application being tested.
read / write
application Application<T>?
The application being tested. [...]
channel → T
The channel of the running application. [...]
hashCode int
The hash code for this object. [...]
read-only, inherited
options ApplicationOptions
Application options for the application being tested. [...]
read / write
runtimeType Type
A representation of the runtime type of the object.
read-only, inherited


afterStart() Future
Override this method to provide post-startup behavior for the application under test. [...]
beforeStart() Future
Override this method to provide configuration for the application under test. [...]
install({bool restartForEachTest = false}) → void
Installs this handler to automatically start before tests begin running, [...]
noSuchMethod(Invocation invocation) → dynamic
Invoked when a non-existent method or property is accessed. [...]
onSetUp() Future
Override this method to register a setUp closure. [...]
onTearDown() Future
Override this method to register a tearDown closure. [...]
start() Future
Initializes a test application and starts it. [...]
stop() Future
Stops the test application from running. [...]
toString() String
A string representation of this object. [...]


operator ==(Object other) bool
The equality operator. [...]