aim_server_testing 0.1.0
aim_server_testing: ^0.1.0 copied to clipboard
Testing utilities for the Aim framework. Provides test helpers, matchers, and mock objects for testing Aim applications.
0.1.0 #
Major Refactoring #
- Simplified TestClient implementation: Refactored to use
Aim.handle()method instead of reimplementing middleware chain- Reduced code complexity by ~40% (253 lines → 145 lines)
- Removed internal
_executeMiddlewareChainmethod (~70 lines) - Improved maintainability by reducing dependency on Aim's internal implementation
New Features #
TestResponse Enhancements
- Body caching: Response body is now cached after first read (Stream can only be read once)
- Detailed status code helpers (properties):
isOk- 200 OKisCreated- 201 CreatedisNoContent- 204 No ContentisBadRequest- 400 Bad RequestisUnauthorized- 401 UnauthorizedisForbidden- 403 ForbiddenisNotFound- 404 Not FoundisInternalServerError- 500 Internal Server Error
- JSON accessors:
jsonMap- Get response body as JSON Map (cached)jsonList- Get response body as JSON List (cached)
Custom Matchers
- Specific status code matchers:
isOk()- 200 OKisCreated()- 201 CreatedisNoContent()- 204 No ContentisBadRequest()- 400 Bad RequestisUnauthorized()- 401 UnauthorizedisForbidden()- 403 ForbiddenisNotFound()- 404 Not FoundisInternalServerError()- 500 Internal Server Error
Breaking Changes #
- Removed test_middleware.dart: Removed internal testing utilities that were not useful for application developers
- Removed
SpyMiddleware,ExecutionTracker,conditionalMiddleware,timeoutMiddleware,headerMiddleware,errorThrowingMiddleware,mockAuthMiddleware - Focus shifted to core testing functionality:
TestClient,TestRequestBuilder, and matchers
- Removed
Dependencies #
- Updated
aim_serverdependency from0.0.4to0.0.5
Migration Guide #
Body Caching
No migration needed. Body methods now cache automatically:
final response = await client.get('/data');
final body1 = await response.bodyAsString(); // Reads from stream
final body2 = await response.bodyAsString(); // Returns cached value
New Status Helpers
Use new convenience helpers instead of hasStatus():
// Before
expect(response, hasStatus(200));
expect(response, hasStatus(201));
// After (more readable)
expect(response, isOk());
expect(response, isCreated());
// Or use properties
expect(response.isOk, isTrue);
expect(response.isCreated, isTrue);
Removed Test Middleware
If you were using test middleware helpers, replace them with custom implementations:
// SpyMiddleware replacement (if needed)
final callCount = 0;
app.use((c, next) async {
callCount++;
await next();
});
0.0.1 #
Initial release of aim_server_testing - Testing utilities for the Aim framework.
Features #
-
TestClient: Test Aim applications without starting an HTTP server
- Support for all HTTP methods: GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS
- Custom headers and query parameters
- JSON and text body support
-
TestRequestBuilder: Fluent API for building test requests
- Method chaining for headers, query parameters, and body
- JSON and text body support
-
Custom Matchers: Convenient matchers for response validation
hasStatus(int statusCode)- Status code validationhasHeader(String name, String value)- Header validationisSuccessful()- 2xx status codesisClientError()- 4xx status codesisServerError()- 5xx status codes
-
TestResponse: Wrapper for Response with helper methods
bodyAsString()- Get body as stringbodyAsJson()- Parse body as JSONheader(name)- Get specific header- Status check properties:
isSuccessful,isClientError,isServerError
Dependencies #
aim_server: 0.0.4test: ^1.25.6