Skip to content

Instantly share code, notes, and snippets.

@emilniklas
Last active March 6, 2020 02:29
Show Gist options
  • Save emilniklas/83796c3e3a283c526d1d to your computer and use it in GitHub Desktop.
Save emilniklas/83796c3e3a283c526d1d to your computer and use it in GitHub Desktop.
The Three Rules of TDD in Dart
// T1 – Empty test (Rule 3)
import 'package:test/test.dart';
import 'b-production-1.dart';
main() {
}
// P1 – Empty production file (Rule 1)
// T2 – (Rule 2)
import 'package:test/test.dart';
import 'd-production-2.dart';
main() {
test('it works', () {
doStuff(); // NoSuchMethodError – time to implement the function (Rule 2)
});
}
// P2 – (Rule 3)
doStuff() {} // Analyzer is happy. Time to return to test (Rule 1)
// T3 – (Rule 2)
import 'package:test/test.dart';
import 'f-production-3.dart';
main() {
test('it works', () {
expect(doStuff(), 'some value'); // Fails: <null != 'some value'> Time to implement (Rule 2)
});
}
// P3 – (Rule 3)
doStuff() {
return 'some value'; // Test passes, return to test. (Rule 1)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment