Instances of this class are used during testing to make testing an HTTP server more convenient.
A TestClient is used to execute HTTP requests during tests. The client is configured to target a 'test' instance of the application under test. The HTTP responses returned from the application are wrapped in instances of TestResponse, which are easy to test using hasResponse and hasStatus test matchers.
Constructors
- TestClient(Application app)
-
Creates an instance that targets the configured
app
. - TestClient.fromConfig(ApplicationConfiguration config, { bool useHTTPS: false })
-
Creates an instance from an ApplicationConfiguration.
- TestClient.onPort(int port)
-
Creates an instance that targets http://localhost:
port
.
Properties
- baseURL → String
-
The base URL that requests will be made against.
read / write - clientID → String
-
When making a clientAuthenticatedRequest, this client ID will be used if none is provided.
read / write - clientSecret → String
-
When making a clientAuthenticatedRequest, this client secret will be used if none is provided.
read / write - defaultAccessToken → String
-
When making an authenticatedRequest, this access token will be used if none is provided.
read / write - defaultHeaders → Map<String, String>
-
Default headers to be added to any requests made by this client.
read / write - hashCode → int
-
The hash code for this object.
read-only, inherited - runtimeType → Type
-
A representation of the runtime type of the object.
read-only, inherited
Operators
-
operator ==(
other) → bool -
The equality operator.
inherited
Methods
-
authenticatedRequest(
String path, { String accessToken: null }) → TestRequest -
Executes a request with a Bearer Authorization header to the application under test.
-
clientAuthenticatedRequest(
String path, { String clientID: null, String clientSecret: null }) → TestRequest -
Executes a request with a Basic Authorization header to the application under test.
-
close(
) → void -
Closes this instances underlying HTTP client.
-
request(
String path) → TestRequest -
Executes a request with no Authorization header to the application under test.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a non-existent method or property is accessed.
inherited -
toString(
) → String -
Returns a string representation of this object.
inherited