Upload
matt-norris
View
454
Download
0
Embed Size (px)
DESCRIPTION
Talk given at Google Developer Group NYC in February 2014 on Dart unit testing.
Citation preview
Dart Unit TestingMatt Norris
@MattNorrisMe
What will we cover?
Client testsServer tests
Why test?
I always mess up some mundane detail!
I must have put a decimal point in the wrong place.
Client tests
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
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
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
HTML unit test
Headless HTML unit test$ content_shell --dump-render-tree web/test_index.html
Content-Type: text/plainPASSAll 2 tests passedCollapse All
Server
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);); }); ...
Server tests
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'); ...
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'); ...
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'); ...
VM unit tests$ dart server_tests.dart
PASS: HashURL
What did we cover?
Client testsServer tests
What should you do?
Try DartTest thingsDeploy!
Such reference... much testing
Projectgithub.com/mattnorris/dart-url-shortener
Original talkyoutu.be/22pE1IP-yoY
Continuous Integration in the Clouddrone.io
Thank you!Questions?