Dart Unit Testing
Matt Norris
@MattNorrisMe
What will we cover?

Client tests
Server tests
Why test?
I must have put a decimal point in the wrong place.

I always mess up some mundane detail!
Client tests
HTML unit test
test_index.dart
import 'package:unittest/unittest.dart';
import 'package:unittest/html_enhanced_config.dart...
HTML unit test
test_index.dart
import 'package:unittest/unittest.dart';
import 'package:unittest/html_enhanced_config.dart...
HTML unit test
test_index.dart
import 'package:unittest/unittest.dart';
import 'package:unittest/html_enhanced_config.dart...
HTML unit test
Headless HTML unit test
$ content_shell --dump-render-tree web/test_index.html

Content-Type: text/plain
PASS
All 2 tests ...
Server
server.dart
void main() {
...
app.post("/").listen((request) {
String url = request.param('url');
String hash = toHash(url...
Server tests
server_tests.dart
import 'package:unittest/unittest.dart';
import 'package:unittest/vm_config.dart';
import 'server.dart' ...
server_tests.dart
import 'package:unittest/unittest.dart';
import 'package:unittest/vm_config.dart';
import 'server.dart' ...
server_tests.dart
import 'package:unittest/unittest.dart';
import 'package:unittest/vm_config.dart';
import 'server.dart' ...
VM unit tests
$ dart server_tests.dart
PASS: HashURL
What did we cover?

Client tests
Server tests
What should you do?

Try Dart
Test things
Deploy!
Such reference... much testing
Project
github.com/mattnorris/dart-url-shortener
Original talk
youtu.be/22pE1IP-yoY
Continu...
Thank you!
Questions?
Dart Unit Testing
Dart Unit Testing
Upcoming SlideShare
Loading in...5
×

Dart Unit Testing

799

Published on

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

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
799
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
1
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Dart Unit Testing

  1. 1. Dart Unit Testing Matt Norris @MattNorrisMe
  2. 2. What will we cover? Client tests Server tests
  3. 3. Why test?
  4. 4. I must have put a decimal point in the wrong place. I always mess up some mundane detail!
  5. 5. Client tests
  6. 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); });
  7. 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); });
  8. 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); });
  9. 9. HTML unit test
  10. 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
  11. 11. Server
  12. 12. server.dart void main() { ... app.post("/").listen((request) { String url = request.param('url'); String hash = toHash(url); client.set(hash, url).then((_)=>request.response.json(hash);); }); ...
  13. 13. Server tests
  14. 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'); ...
  15. 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'); ...
  16. 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'); ...
  17. 17. VM unit tests $ dart server_tests.dart PASS: HashURL
  18. 18. What did we cover? Client tests Server tests
  19. 19. What should you do? Try Dart Test things Deploy!
  20. 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
  21. 21. Thank you! Questions?
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×