TestApp class

Test application wrapper for testing Supafast applications.

Provides a convenient interface for testing HTTP endpoints by automatically managing server lifecycle, port allocation, and HTTP client creation. Designed for use in unit and integration tests.

Example:

void main() {
  group('API Tests', () {
    late TestApp testApp;

    setUp(() async {
      final app = Supafast();
      app.get('/hello', (req, res) => res.send('Hello World'));

      testApp = TestApp(app);
      await testApp.start();
    });

    tearDown(() async {
      await testApp.close();
    });

    test('GET /hello returns greeting', () async {
      final response = await testApp.get('/hello').send();
      expect(response.statusCode, 200);
      expect(response.body, 'Hello World');
    });
  });
}

Features:

  • Automatic port allocation to avoid conflicts
  • HTTP client management with proper timeouts
  • Convenience methods for all HTTP verbs
  • Clean lifecycle management
  • Support for both localhost and custom hostnames

Constructors

TestApp(Supafast app)
Creates a test wrapper for the given Supafast application.

Properties

app → Supafast
The Supafast application instance being tested.
final
baseUrl → String
Get the base URL for the test server.
no setter
hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

close() → Future<void>
Stop the test server and clean up resources.
delete(String path) → TestRequest
Create a DELETE request for testing.
get(String path) → TestRequest
Create a GET request for testing.
Create a HEAD request for testing.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
options(String path) → TestRequest
Create an OPTIONS request for testing.
patch(String path) → TestRequest
Create a PATCH request for testing.
post(String path) → TestRequest
Create a POST request for testing.
put(String path) → TestRequest
Create a PUT request for testing.
request(String method, String path) → TestRequest
Create a request with a custom HTTP method.
start({String hostname = 'localhost'}) → Future<void>
Start the test server on a random available port.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited