Dart Unit Testing

Download Dart Unit Testing

Post on 26-Dec-2014

426 views

Category:

Technology

0 download

Embed Size (px)

DESCRIPTION

Talk given at Google Developer Group NYC in February 2014 on Dart unit testing.

TRANSCRIPT

<ul><li> 1. Dart Unit Testing Matt Norris @MattNorrisMe </li> <li> 2. What will we cover? Client tests Server tests </li> <li> 3. Why test? </li> <li> 4. I must have put a decimal point in the wrong place. I always mess up some mundane detail! </li> <li> 5. Client tests </li> <li> 6. HTML unit test test_index.dart import 'package:unittest/unittest.dart'; import 'package:unittest/html_enhanced_config.dart'; ... main() { useHtmlEnhancedConfiguration(); test("url includes scheme", () { expect(isValidUrl(www.dartlang.org), false); expect(isValidUrl(http://www.dartlang.org), true); }); </li> <li> 7. HTML unit test test_index.dart import 'package:unittest/unittest.dart'; import 'package:unittest/html_enhanced_config.dart'; ... main() { useHtmlEnhancedConfiguration(); test("url includes scheme", () { expect(isValidUrl(www.dartlang.org), false); expect(isValidUrl(http://www.dartlang.org), true); }); </li> <li> 8. HTML unit test test_index.dart import 'package:unittest/unittest.dart'; import 'package:unittest/html_enhanced_config.dart'; ... main() { useHtmlEnhancedConfiguration(); test("url includes scheme", () { expect(isValidUrl(www.dartlang.org), false); expect(isValidUrl(http://www.dartlang.org), true); }); </li> <li> 9. HTML unit test </li> <li> 10. Headless HTML unit test $ content_shell --dump-render-tree web/test_index.html Content-Type: text/plain PASS All 2 tests passed Collapse All </li> <li> 11. Server </li> <li> 12. server.dart void main() { ... app.post("/").listen((request) { String url = request.param('url'); String hash = toHash(url); client.set(hash, url).then((_)=&gt;request.response.json(hash);); }); ... </li> <li> 13. Server tests </li> <li> 14. server_tests.dart import 'package:unittest/unittest.dart'; import 'package:unittest/vm_config.dart'; import 'server.dart' as server; void main() { useVMConfiguration(); String URL = 'http://www.meetup.com/gdg-silicon-valley; test('HashURL', () { expect(server.toHash(URL), isNotNull); expect(server.toHash(URL), '287b6d95'); ... </li> <li> 15. server_tests.dart import 'package:unittest/unittest.dart'; import 'package:unittest/vm_config.dart'; import 'server.dart' as server; void main() { useVMConfiguration(); String URL = 'http://www.meetup.com/gdg-silicon-valley; test('HashURL', () { expect(server.toHash(URL), isNotNull); expect(server.toHash(URL), '287b6d95'); ... </li> <li> 16. server_tests.dart import 'package:unittest/unittest.dart'; import 'package:unittest/vm_config.dart'; import 'server.dart' as server; void main() { useVMConfiguration(); String URL = 'http://www.meetup.com/gdg-silicon-valley; test('HashURL', () { expect(server.toHash(URL), isNotNull); expect(server.toHash(URL), '287b6d95'); ... </li> <li> 17. VM unit tests $ dart server_tests.dart PASS: HashURL </li> <li> 18. What did we cover? Client tests Server tests </li> <li> 19. What should you do? Try Dart Test things Deploy! </li> <li> 20. Such reference... much testing Project github.com/mattnorris/dart-url-shortener Original talk youtu.be/22pE1IP-yoY Continuous Integration in the Cloud drone.io </li> <li> 21. Thank you! Questions? </li> </ul>