23
Dart Unit Testing Matt Norris @MattNorrisMe

Dart Unit Testing

Embed Size (px)

DESCRIPTION

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

Citation preview

Page 1: Dart Unit Testing

Dart Unit TestingMatt Norris

@MattNorrisMe

Page 2: Dart Unit Testing

What will we cover?

Client testsServer tests

Page 3: Dart Unit Testing

Why test?

Page 4: Dart Unit Testing

I always mess up some mundane detail!

I must have put a decimal point in the wrong place.

Page 5: Dart Unit Testing
Page 6: Dart Unit Testing

Client tests

Page 7: Dart Unit Testing

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); });

HTML unit test

Page 8: Dart Unit Testing

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); });

HTML unit test

Page 9: Dart Unit Testing

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); });

HTML unit test

Page 10: Dart Unit Testing

HTML unit test

Page 11: Dart Unit Testing
Page 12: Dart Unit Testing

Headless HTML unit test$ content_shell --dump-render-tree web/test_index.html

Content-Type: text/plainPASSAll 2 tests passedCollapse All

Page 13: Dart Unit Testing

Server

Page 14: Dart Unit Testing

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);); }); ...

Page 15: Dart Unit Testing

Server tests

Page 16: Dart Unit Testing

server_tests.dartimport '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'); ...

Page 17: Dart Unit Testing

server_tests.dartimport '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'); ...

Page 18: Dart Unit Testing

server_tests.dartimport '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'); ...

Page 19: Dart Unit Testing

VM unit tests$ dart server_tests.dart

PASS: HashURL

Page 20: Dart Unit Testing

What did we cover?

Client testsServer tests

Page 21: Dart Unit Testing

What should you do?

Try DartTest thingsDeploy!

Page 22: Dart Unit Testing

Such reference... much testing

Projectgithub.com/mattnorris/dart-url-shortener

Original talkyoutu.be/22pE1IP-yoY

Continuous Integration in the Clouddrone.io

Page 23: Dart Unit Testing

Thank you!Questions?