| Index: README.md
|
| diff --git a/README.md b/README.md
|
| index c598b8843f525f5c967dac96c5b397a15afe705e..51c4ec08646c1a20ff88f399359c07b23970e824 100644
|
| --- a/README.md
|
| +++ b/README.md
|
| @@ -76,6 +76,35 @@ void main() {
|
| }
|
| ```
|
|
|
| +You can use the [`setUp()`][setUp] and [`tearDown()`][tearDown] functions to
|
| +share code between tests. The `setUp()` callback will run before every test in a
|
| +group or test suite, and `tearDown()` will run after. `tearDown()` will run even
|
| +if a test fails, to ensure that it has a chance to clean up after itself.
|
| +
|
| +```dart
|
| +import "package:test/test.dart";
|
| +
|
| +void main() {
|
| + var server;
|
| + var url;
|
| + setUp(() async {
|
| + server = await HttpServer.bind('localhost', 0);
|
| + url = Uri.parse("http://${server.address.host}:${server.port}");
|
| + });
|
| +
|
| + tearDown(() async {
|
| + await server.close(force: true);
|
| + server = null;
|
| + url = null;
|
| + });
|
| +
|
| + // ...
|
| +}
|
| +```
|
| +
|
| +[setUp]: http://www.dartdocs.org/documentation/test/latest/index.html#test/test@id_setUp
|
| +[tearDown]: http://www.dartdocs.org/documentation/test/latest/index.html#test/test@id_tearDown
|
| +
|
| ## Running Tests
|
|
|
| A single test file can be run just using `pub run test:test path/to/test.dart`
|
|
|