Skip to content

Commit

Permalink
Talk about setUp and tearDown in the README.
Browse files Browse the repository at this point in the history
Closes #347

R=kevmoo@google.com

Review URL: https://codereview.chromium.org//1397903003 .
  • Loading branch information
nex3 committed Oct 13, 2015
1 parent 1bd68b3 commit 9f8c52d
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down

0 comments on commit 9f8c52d

Please sign in to comment.