Last active
March 6, 2020 02:29
-
-
Save emilniklas/83796c3e3a283c526d1d to your computer and use it in GitHub Desktop.
The Three Rules of TDD in Dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// T1 – Empty test (Rule 3) | |
import 'package:test/test.dart'; | |
import 'b-production-1.dart'; | |
main() { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// P1 – Empty production file (Rule 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// P2 – (Rule 3) | |
doStuff() {} // Analyzer is happy. Time to return to test (Rule 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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