Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(214)

Unified Diff: README.md

Issue 1397903003: Talk about setUp and tearDown in the README. (Closed) Base URL: git@github.com:dart-lang/test@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pubspec.yaml » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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`
« no previous file with comments | « no previous file | pubspec.yaml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698