Created
February 25, 2014 17:46
-
-
Save shailen/9214040 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// When to use expectAsync? | |
import 'package:unittest/unittest.dart'; | |
import 'dart:async'; | |
syncAdd(x, y) => x + y; | |
asyncAdd(x, y) => new Future.value(x + y); | |
void main() { | |
test('testing sync code synchronously', () { | |
expect(syncAdd(3, 4), 7); | |
}); | |
test('testing sync code asynchronously', () { | |
new Future(expectAsync(() { | |
expect(syncAdd(3, 4), 7); | |
})); | |
}); | |
test('testing async code synchronously', () { | |
asyncAdd(3, 4).then((result) { | |
expect(result, 7); | |
}); | |
}); | |
test('testing async code asynchronously', () { | |
new Future(expectAsync(() { | |
asyncAdd(3, 4).then((result) { | |
expect(result, 7); | |
}); | |
})); | |
}); | |
test("testing async without expectAsync(). DON'T DO THIS.", () { | |
new Future(() { | |
// Test does not run!!!!!!!! | |
expect(1, 2); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment