Testing

Testing

Dart already has fantastic testing support, through a library of testing helpers that will make test writing faster. The following functions are exported by package:angel_test, and will make your testing much easier.

connectTo

Full definition

This function will start app on an available port, and return a TestClient instance (based on package:angel_client) configured to send requests to the server. The client also supports session manipulation.

  1. main() {
  2. TestClient client;
  3. setUp(() async {
  4. client = await connectTo(myApp);
  5. });
  6. // Shut down server, and cancel pending requests
  7. tearDown(() => client.close());
  8. test('hello', () async {
  9. // The server URL is automatically prepended to paths.
  10. // This returns an http.Response. :)
  11. var response = await client.get('/hello');
  12. });
  13. }

isJson

A Matcher that asserts that the given http.Response equals value when decoded as JSON. This uses test.equals internally, so anything that would pass that matcher passes this one.

hasStatus

A Matcher that asserts the given http.Response has the given status code.

More Matchers

The complete set of angel_test Matchers can be found here.

Next Up…

  1. Find out how to handle errors in an Angel application.
  2. Learn how to use the handy Angel CLI.